From 6182a99eeda03d915c65ceb5b6af294e11800244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Mon, 12 Jun 2023 16:45:45 +0200 Subject: [PATCH] fix: prevent throwing Uncaught error on cancel --- .../contrib/output/common/outputChannelModel.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/output/common/outputChannelModel.ts b/src/vs/workbench/contrib/output/common/outputChannelModel.ts index 88cc5df03cf..07926124b30 100644 --- a/src/vs/workbench/contrib/output/common/outputChannelModel.ts +++ b/src/vs/workbench/contrib/output/common/outputChannelModel.ts @@ -22,6 +22,7 @@ import { VSBuffer } from 'vs/base/common/buffer'; import { ILogger, ILoggerService, ILogService } from 'vs/platform/log/common/log'; import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation'; import { OutputChannelUpdateMode } from 'vs/workbench/services/output/common/output'; +import { isCancellationError } from 'vs/base/common/errors'; export interface IOutputChannelModel extends IDisposable { readonly onDispose: Event; @@ -61,7 +62,11 @@ class OutputFileListener extends Disposable { private poll(): void { const loop = () => this.doWatch().then(() => this.poll()); - this.syncDelayer.trigger(loop); + this.syncDelayer.trigger(loop).catch(error => { + if (!isCancellationError(error)) { + throw error; + } + }); } private async doWatch(): Promise { @@ -206,7 +211,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel this.doUpdateModel(model, [EditOperation.delete(model.getFullModelRange())], VSBuffer.fromString('')); } - private async appendContent(model: ITextModel, immediate: boolean, token: CancellationToken): Promise { + private appendContent(model: ITextModel, immediate: boolean, token: CancellationToken): void { this.appendThrottler.trigger(async () => { /* Abort if operation is cancelled */ if (token.isCancellationRequested) { @@ -234,7 +239,11 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel const lastLineMaxColumn = model.getLineMaxColumn(lastLine); const edits = [EditOperation.insert(new Position(lastLine, lastLineMaxColumn), contentToAppend.toString())]; this.doUpdateModel(model, edits, contentToAppend); - }, immediate ? 0 : undefined); + }, immediate ? 0 : undefined).catch(error => { + if (!isCancellationError(error)) { + throw error; + } + }); } private async replaceContent(model: ITextModel, token: CancellationToken): Promise {