Skip to content

Commit 31d155e

Browse files
committed
feat: Make unexpected errors catchable
1 parent 5e108bb commit 31d155e

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/languageClient.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export class LanguageClientManager implements LanguageClient {
112112
}
113113

114114
private handleError = (error: Error) => {
115+
monaco.errorHandler.onUnexpectedError(new Error('[LSP] Language client error', {
116+
cause: error
117+
}))
115118
this.onErrorEmitter.fire(error)
116119
this.updateStatus('error')
117120

@@ -122,7 +125,9 @@ export class LanguageClientManager implements LanguageClient {
122125
try {
123126
await loadExtensionConfigurations([this.id], this.useMutualizedProxy)
124127
} catch (error) {
125-
console.error('Unable to load extension configuration', error)
128+
monaco.errorHandler.onUnexpectedError(new Error('[LSP] Unable to load extension configuration', {
129+
cause: error as Error
130+
}))
126131
}
127132
if (!this.isDisposed()) {
128133
this._start()
@@ -234,8 +239,10 @@ export class LanguageClientManager implements LanguageClient {
234239
delay(maxInitializeDuration ?? 15_000)
235240
])
236241
disposableCollection.dispose()
237-
}, error => {
238-
console.error('[LSP]', 'Error while waiting for the language client to be ready', error)
242+
}, (error: Error) => {
243+
monaco.errorHandler.onUnexpectedError(new Error(`[LSP] Error while waiting for the ${this.id} language client to be ready`, {
244+
cause: error
245+
}))
239246
})
240247
break
241248
}

src/services.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ function autoSaveModels (services: CgMonacoServices): Disposable {
4040
}
4141
timeoutMap.set(e.textDocument.uri, window.setTimeout(() => {
4242
timeoutMap.delete(e.textDocument.uri)
43-
services.workspace.saveDocument(e.textDocument, TextDocumentSaveReason.AfterDelay).catch(err => {
44-
console.error('[LSP]', `Unable to save the document ${e.textDocument.uri.toString()}`, err)
43+
services.workspace.saveDocument(e.textDocument, TextDocumentSaveReason.AfterDelay).catch((error: Error) => {
44+
monaco.errorHandler.onUnexpectedError(new Error(`[LSP] Unable to save the document ${e.textDocument.uri.toString()}`, {
45+
cause: error
46+
}))
4547
})
4648
}, 500))
4749
}))

src/services/CodinGameMonacoWorkspace.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export default class CodinGameMonacoWorkspace extends MonacoWorkspace {
6767

6868
this.onDidSaveTextDocumentEmitter.fire(document)
6969
} catch (err) {
70-
console.error('[LSP]', 'Unable to save file on language server', err)
70+
monaco.errorHandler.onUnexpectedError(new Error(`[LSP] Unable to save file on language server: ${document.uri.toString()}`, {
71+
cause: err as Error
72+
}))
7173
}
7274
}
7375
}

0 commit comments

Comments
 (0)