Skip to content

Commit d9aec26

Browse files
committed
fix: Improve error messages in Deepnote notebook command listener
- Updated error handling in the DeepnoteNotebookCommandListener to use localized messages for better user experience. - Adjusted logic for variable name suffix checks to ensure correct prefix usage. Signed-off-by: Tomas Kislan <[email protected]>
1 parent b70bcec commit d9aec26

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/notebooks/deepnote/deepnoteNotebookCommandListener.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
NotebookEdit,
88
NotebookRange,
99
NotebookCell,
10-
NotebookEditorRevealType
10+
NotebookEditorRevealType,
11+
l10n
1112
} from 'vscode';
1213
import z from 'zod';
1314

@@ -106,7 +107,7 @@ export function getNextDeepnoteVariableName(cells: NotebookCell[], prefix: 'df'
106107

107108
const maxDeepnoteVariableNamesSuffixNumber =
108109
deepnoteVariableNames.reduce<number | null>((acc, name) => {
109-
if (!name.startsWith(prefix)) {
110+
if (!name.startsWith(`${prefix}_`)) {
110111
return acc;
111112
}
112113

@@ -178,7 +179,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
178179
public async addSqlBlock(): Promise<void> {
179180
const editor = window.activeNotebookEditor;
180181
if (!editor) {
181-
throw new Error('No active notebook editor found');
182+
throw new Error(l10n.t('No active notebook editor found'));
182183
}
183184
const document = editor.notebook;
184185
const selection = editor.selection;
@@ -209,7 +210,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
209210
edit.set(document.uri, [nbEdit]);
210211
});
211212
if (result !== true) {
212-
throw new Error('Failed to insert SQL block');
213+
throw new Error(l10n.t('Failed to insert SQL block'));
213214
}
214215

215216
const notebookRange = new NotebookRange(insertIndex, insertIndex + 1);
@@ -222,7 +223,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
222223
public async addBigNumberChartBlock(): Promise<void> {
223224
const editor = window.activeNotebookEditor;
224225
if (!editor) {
225-
throw new Error('No active notebook editor found');
226+
throw new Error(l10n.t('No active notebook editor found'));
226227
}
227228
const document = editor.notebook;
228229
const selection = editor.selection;
@@ -250,7 +251,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
250251
edit.set(document.uri, [nbEdit]);
251252
});
252253
if (result !== true) {
253-
throw new Error('Failed to insert big number chart block');
254+
throw new Error(l10n.t('Failed to insert big number chart block'));
254255
}
255256

256257
const notebookRange = new NotebookRange(insertIndex, insertIndex + 1);
@@ -263,7 +264,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
263264
public async addInputBlock(blockType: InputBlockType): Promise<void> {
264265
const editor = window.activeNotebookEditor;
265266
if (!editor) {
266-
throw new Error('No active notebook editor found');
267+
throw new Error(l10n.t('No active notebook editor found'));
267268
}
268269
const document = editor.notebook;
269270
const selection = editor.selection;
@@ -294,7 +295,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
294295
edit.set(document.uri, [nbEdit]);
295296
});
296297
if (result !== true) {
297-
throw new Error('Failed to insert input block');
298+
throw new Error(l10n.t('Failed to insert input block'));
298299
}
299300

300301
const notebookRange = new NotebookRange(insertIndex, insertIndex + 1);

0 commit comments

Comments
 (0)