Skip to content

Commit b423515

Browse files
committed
Fix unhandled errors
1 parent 4ae1e96 commit b423515

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

src/interactive-window/debugger/jupyter/kernelDebugAdapter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { getInteractiveCellMetadata } from '../../../interactive-window/helpers'
1515
import { KernelDebugAdapterBase } from '../../../notebooks/debugger/kernelDebugAdapterBase';
1616
import { InteractiveCellMetadata } from '../../editor-integration/types';
1717
import { IDebugService } from '../../../platform/common/application/types';
18+
import { noop } from '../../../platform/common/utils/misc';
1819
/**
1920
* KernelDebugAdapter listens to debug messages in order to translate file requests into real files
2021
* (Interactive Window generally executes against a real file)
@@ -75,7 +76,11 @@ export class KernelDebugAdapter extends KernelDebugAdapterBase {
7576
if (message.type === 'response' && this.debugLocationTracker?.onDidSendMessage) {
7677
this.debugLocationTracker.onDidSendMessage(message);
7778
}
78-
return super.handleMessage(message);
79+
const promise = super.handleMessage(message);
80+
// The VS Code debugger class does not support an async `handleMessage`, its supposed to be sync.
81+
// As a result, any errors here will not be handled and they'll be treated as unhandled errors.
82+
promise.catch(noop);
83+
return promise;
7984
}
8085

8186
// Dump content of given cell into a tmp file and return path to file.

src/kernels/common/delayedFutureExecute.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Kernel, KernelMessage } from '@jupyterlab/services';
77
import { traceInfoIfCI } from '../../platform/logging';
88
import { createDeferred } from '../../platform/common/utils/async';
99
import { CancellationError } from 'vscode';
10+
import { noop } from '../../platform/common/utils/misc';
1011

1112
// Wraps a future so that a requestExecute on a session will wait for the previous future to finish before actually executing
1213
export class DelayedFutureExecute
@@ -40,6 +41,8 @@ export class DelayedFutureExecute
4041
private disposeOnDone?: boolean,
4142
private metadata?: JSONObject
4243
) {
44+
// Ensure we don't have any unhandled promises.
45+
this.doneDeferred.promise.catch(noop);
4346
// Setup our request based on the previous link finishing
4447
previousLink.done.then(() => this.requestExecute()).catch((e) => this.doneDeferred.reject(e));
4548

src/kernels/execution/cellExecution.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class CellExecution implements IDisposable {
8282
private _completed?: boolean;
8383
private startTime?: number;
8484
private endTime?: number;
85+
private disposed?: boolean;
8586
private execution?: NotebookCellExecution;
8687
private cancelHandled = false;
8788
private request: Kernel.IShellFuture<KernelMessage.IExecuteRequestMsg, KernelMessage.IExecuteReplyMsg> | undefined;
@@ -217,6 +218,10 @@ export class CellExecution implements IDisposable {
217218
* Or when execution has been cancelled.
218219
*/
219220
public dispose() {
221+
if (this.disposed) {
222+
return;
223+
}
224+
this.disposed = true;
220225
traceCellMessage(this.cell, 'Execution disposed');
221226
disposeAllDisposables(this.disposables);
222227
this.cellExecutionHandler?.dispose();

src/kernels/execution/cellExecutionMessageHandler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class CellExecutionMessageHandler implements IDisposable {
114114
private temporaryExecution?: NotebookCellExecution;
115115
private previousResultsToRestore?: NotebookCellExecutionSummary;
116116
private cellHasErrorsInOutput?: boolean;
117+
private disposed?: boolean;
117118

118119
public get hasErrorOutput() {
119120
return this.cellHasErrorsInOutput === true;
@@ -235,7 +236,11 @@ export class CellExecutionMessageHandler implements IDisposable {
235236
* Or when execution has been cancelled.
236237
*/
237238
public dispose() {
238-
traceCellMessage(this.cell, 'Execution disposed');
239+
if (this.disposed) {
240+
return;
241+
}
242+
this.disposed = true;
243+
traceCellMessage(this.cell, 'Execution Message Handler disposed');
239244
disposeAllDisposables(this.disposables);
240245
this.prompts.forEach((item) => item.dispose());
241246
this.prompts.clear();

src/kernels/execution/kernelExecution.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { noop } from '../../platform/common/utils/misc';
3636
*/
3737
export class BaseKernelExecution<TKernel extends IBaseKernel = IBaseKernel> implements IDisposable {
3838
protected readonly disposables: IDisposable[] = [];
39+
private disposed?: boolean;
3940
private _interruptPromise?: Promise<InterruptResult>;
4041
private _restartPromise?: Promise<void>;
4142
protected get restarting() {
@@ -100,6 +101,10 @@ export class BaseKernelExecution<TKernel extends IBaseKernel = IBaseKernel> impl
100101
await this._restartPromise;
101102
}
102103
public dispose() {
104+
if (this.disposed) {
105+
return;
106+
}
107+
this.disposed = true;
103108
traceInfoIfCI(`Dispose KernelExecution`);
104109
this.disposables.forEach((d) => d.dispose());
105110
}

0 commit comments

Comments
 (0)