From 4c24043cc86556506c445b460525ca93f16ef831 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Tue, 22 Oct 2019 18:19:36 -0700 Subject: [PATCH] Add Option to Halt Notebook when Error Occurs in SQL Kernel (#7884) * Add Option to Halt Nb when Error Occurs * PR comments --- .../parts/notebook/browser/notebook.contribution.ts | 13 +++++++++++++ .../notebook/browser/sql/sqlSessionManager.ts | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts b/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts index a8767cb695..78376bd1bf 100644 --- a/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts +++ b/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts @@ -160,6 +160,19 @@ configurationRegistry.registerConfiguration({ } }); +configurationRegistry.registerConfiguration({ + 'id': 'notebook', + 'title': 'Notebook', + 'type': 'object', + 'properties': { + 'notebook.sqlStopOnError': { + 'type': 'boolean', + 'default': true, + 'description': localize('notebook.sqlStopOnError', "SQL kernel: stop Notebook execution when error occurs in a cell.") + } + } +}); + registerAction({ id: 'workbench.books.action.focusBooksExplorer', handler: async (accessor) => { diff --git a/src/sql/workbench/services/notebook/browser/sql/sqlSessionManager.ts b/src/sql/workbench/services/notebook/browser/sql/sqlSessionManager.ts index d05c434194..91c55d5d4e 100644 --- a/src/sql/workbench/services/notebook/browser/sql/sqlSessionManager.ts +++ b/src/sql/workbench/services/notebook/browser/sql/sqlSessionManager.ts @@ -30,6 +30,7 @@ export const sqlKernelError: string = localize("sqlKernelError", "SQL kernel err export const MAX_ROWS = 5000; export const NotebookConfigSectionName = 'notebook'; export const MaxTableRowsConfigName = 'maxTableRows'; +export const SqlStopOnErrorConfigName = 'sqlStopOnError'; const languageMagics: ILanguageMagic[] = [{ language: 'Python', @@ -379,6 +380,8 @@ export class SQLFuture extends Disposable implements FutureInternal { private configuredMaxRows: number = MAX_ROWS; private _outputAddedPromises: Promise[] = []; private _querySubsetResultMap: Map = new Map(); + private _errorOccurred: boolean = false; + private _stopOnError: boolean = true; constructor( private _queryRunner: QueryRunner, private _executionCount: number | undefined, @@ -392,6 +395,7 @@ export class SQLFuture extends Disposable implements FutureInternal { if (maxRows && maxRows > 0) { this.configuredMaxRows = maxRows; } + this._stopOnError = !!config[SqlStopOnErrorConfigName]; } } @@ -426,7 +430,7 @@ export class SQLFuture extends Disposable implements FutureInternal { channel: 'shell', type: 'execute_reply', content: { - status: 'ok', + status: this._errorOccurred && this._stopOnError ? 'error' : 'ok', execution_count: this._executionCount }, header: undefined, @@ -619,6 +623,8 @@ export class SQLFuture extends Disposable implements FutureInternal { } private convertToError(msg: IResultMessage | string): nb.IIOPubMessage { + this._errorOccurred = true; + if (msg) { let msgData = typeof msg === 'string' ? msg : msg.message; return {