Skip to content

Commit

Permalink
fix bug that causes code interrupt to fail the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
allen-li1231 committed Jan 20, 2024
1 parent 6c47fce commit 692d157
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ class BasicService {
},
(error) => {
logDebug(error);
if (error.code === "ERR_CANCELED") {
return error;
}

let url = error.request?.path;

if (!error.response) {
window.showErrorMessage(`Error calling ${url}: ${error.message}
Possibly due to local network issue`);
possibly due to local network issue`);
}
else if (error.response?.status === 401) {
window.showWarningMessage(
Expand Down
24 changes: 16 additions & 8 deletions src/extension/notebookKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,25 +430,33 @@ export class ZeppelinKernel {
execution.executionOrder = ++this._executionOrder;
execution.start(Date.now());

try {
let cancelTokenSource = this._service?.cancelTokenSource;
execution.token.onCancellationRequested(_ => cancelTokenSource?.cancel());
let cancelTokenSource = this._service?.cancelTokenSource;
execution.token.onCancellationRequested(_ => cancelTokenSource?.cancel());

try {
await this.updateParagraph(cell);

let cellOutput = await this._runParagraph(cell);
execution.replaceOutput(new vscode.NotebookCellOutput(cellOutput));
execution.replaceOutput(new vscode.NotebookCellOutput(cellOutput ?? []));
execution.end(true, Date.now());

} catch (err) {
execution.replaceOutput(
new vscode.NotebookCellOutput([
let cellOutput: vscode.NotebookCellOutput;
if (err instanceof AxiosError && err.code === "ERR_CANCELED") {
cellOutput = new vscode.NotebookCellOutput([
vscode.NotebookCellOutputItem.text("")
]);
}
else {
cellOutput = new vscode.NotebookCellOutput([
vscode.NotebookCellOutputItem.error({
name: err instanceof Error && err.name || 'error',
message: err instanceof Error && err.message || JSON.stringify(err, undefined, 4)
})
])
);
]);
}

execution.replaceOutput(cellOutput);
execution.end(false, Date.now());
}
}
Expand Down

0 comments on commit 692d157

Please sign in to comment.