editors - do not eat error action results

This commit is contained in:
Benjamin Pasero 2022-04-21 07:24:00 +02:00
parent d1ef72c22c
commit 4875bf81b7
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
2 changed files with 17 additions and 5 deletions

View file

@ -158,7 +158,7 @@ export class EditorPanes extends Disposable {
}
const buttons: string[] = [];
if (Array.isArray(errorActions) && errorActions.length > 0) {
if (errorActions && errorActions.length > 0) {
for (const errorAction of errorActions) {
buttons.push(errorAction.label);
}
@ -183,10 +183,14 @@ export class EditorPanes extends Disposable {
);
// Make sure to run any error action if present
if (result.choice !== cancelId && Array.isArray(errorActions)) {
if (result.choice !== cancelId && errorActions) {
const errorAction = errorActions[result.choice];
if (errorAction) {
errorAction.run();
const result = errorAction.run();
if (result instanceof Promise) {
result.catch(error => this.dialogService.show(Severity.Error, toErrorMessage(error)));
}
errorHandled = true; // consider the error as handled!
}
}

View file

@ -5,6 +5,7 @@
import 'vs/css!./media/editorplaceholder';
import { localize } from 'vs/nls';
import Severity from 'vs/base/common/severity';
import { IEditorOpenContext } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
@ -28,6 +29,7 @@ import { editorErrorForeground, editorInfoForeground, editorWarningForeground }
import { Codicon } from 'vs/base/common/codicons';
import { FileChangeType, FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
import { isErrorWithActions, toErrorMessage } from 'vs/base/common/errorMessage';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
export interface IEditorPlaceholderContents {
icon: string;
@ -214,7 +216,8 @@ export class ErrorPlaceholderEditor extends EditorPlaceholder {
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService,
@IInstantiationService instantiationService: IInstantiationService,
@IFileService private readonly fileService: IFileService
@IFileService private readonly fileService: IFileService,
@IDialogService private readonly dialogService: IDialogService
) {
super(ErrorPlaceholderEditor.ID, telemetryService, themeService, storageService, instantiationService);
}
@ -241,7 +244,12 @@ export class ErrorPlaceholderEditor extends EditorPlaceholder {
actions = error.actions.map(action => {
return {
label: action.label,
run: () => action.run()
run: () => {
const result = action.run();
if (result instanceof Promise) {
result.catch(error => this.dialogService.show(Severity.Error, toErrorMessage(error)));
}
}
};
});
} else if (group) {