Skip to content

Commit fe2ab9f

Browse files
committed
Oops
1 parent 7cfca70 commit fe2ab9f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/client/common/application/notebook.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,39 @@ import { inject, injectable } from 'inversify';
55
import { DocumentSelector, Event, EventEmitter, workspace } from 'vscode';
66
import type { notebook, NotebookConcatTextDocument, NotebookDocument } from 'vscode-proposed';
77
import { UseProposedApi } from '../constants';
8+
import { traceError } from '../logger';
89
import { IApplicationEnvironment, IVSCodeNotebook } from './types';
910

1011
@injectable()
1112
export class VSCodeNotebook implements IVSCodeNotebook {
1213
public get onDidOpenNotebookDocument(): Event<NotebookDocument> {
13-
const onDidOpenNotebookDocument =
14-
this.notebook.onDidOpenNotebookDocument ?? (workspace as any).onDidOpenNotebookDocument;
15-
return this.canUseNotebookApi ? onDidOpenNotebookDocument : new EventEmitter<NotebookDocument>().event;
14+
try {
15+
const onDidOpenNotebookDocument =
16+
this.notebook.onDidOpenNotebookDocument ?? (workspace as any).onDidOpenNotebookDocument;
17+
return this.canUseNotebookApi ? onDidOpenNotebookDocument : new EventEmitter<NotebookDocument>().event;
18+
} catch (ex) {
19+
traceError(`Failed to get event handler onDidOpenNotebookDocument`, ex);
20+
return new EventEmitter<NotebookDocument>().event;
21+
}
1622
}
1723
public get onDidCloseNotebookDocument(): Event<NotebookDocument> {
18-
const onDidCloseNotebookDocument =
19-
this.notebook.onDidCloseNotebookDocument ?? (workspace as any).onDidCloseNotebookDocument;
20-
return this.canUseNotebookApi ? onDidCloseNotebookDocument : new EventEmitter<NotebookDocument>().event;
24+
try {
25+
const onDidCloseNotebookDocument =
26+
this.notebook.onDidCloseNotebookDocument ?? (workspace as any).onDidCloseNotebookDocument;
27+
return this.canUseNotebookApi ? onDidCloseNotebookDocument : new EventEmitter<NotebookDocument>().event;
28+
} catch (ex) {
29+
traceError(`Failed to get event handler onDidOpenNotebookDocument`, ex);
30+
return new EventEmitter<NotebookDocument>().event;
31+
}
2132
}
2233
public get notebookDocuments(): ReadonlyArray<NotebookDocument> {
23-
const notebookDocuments = this.notebook.notebookDocuments ?? (workspace as any).notebookDocuments;
24-
return this.canUseNotebookApi ? notebookDocuments : [];
34+
try {
35+
const notebookDocuments = this.notebook.notebookDocuments ?? (workspace as any).notebookDocuments;
36+
return this.canUseNotebookApi ? notebookDocuments : [];
37+
} catch (ex) {
38+
traceError(`Failed to get event handler onDidOpenNotebookDocument`, ex);
39+
return [];
40+
}
2541
}
2642
private get notebook() {
2743
if (!this._notebook) {

0 commit comments

Comments
 (0)