Skip to content

Commit 857a0b5

Browse files
committed
handle strategies failing during apply/discard
fixes microsoft/vscode-internalbacklog#4131
1 parent c67dc5a commit 857a0b5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { renderMarkdown } from 'vs/base/browser/markdownRenderer';
77
import { Barrier, raceCancellationError } from 'vs/base/common/async';
88
import { CancellationTokenSource } from 'vs/base/common/cancellation';
9+
import { toErrorMessage } from 'vs/base/common/errorMessage';
910
import { Emitter, Event } from 'vs/base/common/event';
1011
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
1112
import { isEqual } from 'vs/base/common/resources';
@@ -24,6 +25,7 @@ import { InlineCompletionsController } from 'vs/editor/contrib/inlineCompletions
2425
import { localize } from 'vs/nls';
2526
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2627
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
28+
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
2729
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
2830
import { ILogService } from 'vs/platform/log/common/log';
2931
import { EditResponse, EmptyResponse, ErrorResponse, IInteractiveEditorSessionService, MarkdownResponse, Session, SessionExchange } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
@@ -101,6 +103,7 @@ export class InteractiveEditorController implements IEditorContribution {
101103
@IConfigurationService private readonly _configurationService: IConfigurationService,
102104
@IModelService private readonly _modelService: IModelService,
103105
@INotebookEditorService private readonly _notebookEditorService: INotebookEditorService,
106+
@IDialogService private readonly _dialogService: IDialogService,
104107
@IContextKeyService contextKeyService: IContextKeyService,
105108
) {
106109
this._ctxHasActiveRequest = CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST.bindTo(contextKeyService);
@@ -612,7 +615,13 @@ export class InteractiveEditorController implements IEditorContribution {
612615
if (this._strategy) {
613616
const strategy = this._strategy;
614617
this._strategy = undefined;
615-
await strategy?.apply();
618+
try {
619+
await strategy?.apply();
620+
} catch (err) {
621+
this._dialogService.error(localize('err.apply', "Failed to apply changes.", toErrorMessage(err)));
622+
this._logService.error('[IE] FAILED to apply changes');
623+
this._logService.error(err);
624+
}
616625
strategy?.dispose();
617626
this._messages.fire(Message.END_SESSION);
618627

@@ -626,7 +635,13 @@ export class InteractiveEditorController implements IEditorContribution {
626635
if (this._strategy) {
627636
const strategy = this._strategy;
628637
this._strategy = undefined;
629-
await strategy?.cancel();
638+
try {
639+
await strategy?.cancel();
640+
} catch (err) {
641+
this._dialogService.error(localize('err.discard', "Failed to discard changes.", toErrorMessage(err)));
642+
this._logService.error('[IE] FAILED to discard changes');
643+
this._logService.error(err);
644+
}
630645
strategy?.dispose();
631646
this._messages.fire(Message.END_SESSION);
632647
}

0 commit comments

Comments
 (0)