Skip to content

Commit 56bf25e

Browse files
committed
refactor: Improve error handling in Deepnote notebook command listener
- Removed unused imports and copyright headers. - Enhanced error handling for cell insertion operations by logging errors instead of using a no-operation function. - Updated regex for variable name matching to ensure proper prefix handling. Signed-off-by: Tomas Kislan <tomas@kislan.sk>
1 parent f134660 commit 56bf25e

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/notebooks/deepnote/deepnoteNotebookCommandListener.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// Licensed under the MIT License.
3-
41
import { injectable, inject } from 'inversify';
52
import {
63
commands,
@@ -17,7 +14,6 @@ import { logger } from '../../platform/logging';
1714
import { IExtensionSyncActivationService } from '../../platform/activation/types';
1815
import { IDisposableRegistry } from '../../platform/common/types';
1916
import { Commands } from '../../platform/common/constants';
20-
import { noop } from '../../platform/common/utils/misc';
2117
import { chainWithPendingUpdates } from '../../kernels/execution/notebookUpdater';
2218
import {
2319
DeepnoteBigNumberMetadataSchema,
@@ -102,7 +98,11 @@ export function getNextDeepnoteVariableName(cells: NotebookCell[], prefix: 'df'
10298

10399
const maxDeepnoteVariableNamesSuffixNumber =
104100
deepnoteVariableNames.reduce<number | null>((acc, name) => {
105-
const m = name.match(new RegExp(`^${prefix}_(\\d+)$`));
101+
if (!name.startsWith(prefix)) {
102+
return acc;
103+
}
104+
105+
const m = name.match(/_(\d+)$/);
106106
if (m == null) {
107107
return acc;
108108
}
@@ -189,9 +189,14 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
189189
};
190190
const nbEdit = NotebookEdit.insertCells(insertIndex, [newCell]);
191191
edit.set(document.uri, [nbEdit]);
192-
}).then(() => {
193-
editor.selection = new NotebookRange(insertIndex, insertIndex + 1);
194-
}, noop);
192+
}).then(
193+
() => {
194+
editor.selection = new NotebookRange(insertIndex, insertIndex + 1);
195+
},
196+
(error) => {
197+
logger.error('Error inserting SQL block', error);
198+
}
199+
);
195200
}
196201

197202
private addBigNumberChartBlock(): void {
@@ -223,9 +228,14 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
223228
newCell.metadata = metadata;
224229
const nbEdit = NotebookEdit.insertCells(insertIndex, [newCell]);
225230
edit.set(document.uri, [nbEdit]);
226-
}).then(() => {
227-
editor.selection = new NotebookRange(insertIndex, insertIndex + 1);
228-
}, noop);
231+
}).then(
232+
() => {
233+
editor.selection = new NotebookRange(insertIndex, insertIndex + 1);
234+
},
235+
(error) => {
236+
logger.error('Error inserting big number chart block', error);
237+
}
238+
);
229239
}
230240

231241
private addInputBlock(blockType: InputBlockType): void {
@@ -260,8 +270,13 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
260270
newCell.metadata = metadata;
261271
const nbEdit = NotebookEdit.insertCells(insertIndex, [newCell]);
262272
edit.set(document.uri, [nbEdit]);
263-
}).then(() => {
264-
editor.selection = new NotebookRange(insertIndex, insertIndex + 1);
265-
}, noop);
273+
}).then(
274+
() => {
275+
editor.selection = new NotebookRange(insertIndex, insertIndex + 1);
276+
},
277+
(error) => {
278+
logger.error('Error inserting input block', error);
279+
}
280+
);
266281
}
267282
}

src/notebooks/deepnote/deepnoteNotebookCommandListener.unit.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// Licensed under the MIT License.
3-
41
import { assert } from 'chai';
52
import { DeepnoteNotebookCommandListener, getNextDeepnoteVariableName } from './deepnoteNotebookCommandListener';
63
import { IDisposable } from '../../platform/common/types';

0 commit comments

Comments
 (0)