From b86bdb4fced2ea655982dd750804d263021a3acd Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 5 Feb 2023 14:17:09 -0500 Subject: [PATCH] Improves generic error messaging --- src/commands/copyCurrentBranch.ts | 5 ++-- src/commands/openBranchOnRemote.ts | 6 ++--- src/commands/openBranchesOnRemote.ts | 6 ++--- src/commands/openCommitOnRemote.ts | 7 ++---- src/commands/openComparisonOnRemote.ts | 6 ++--- src/commands/openCurrentBranchOnRemote.ts | 6 ++--- src/commands/openFileOnRemote.ts | 5 ++-- src/commands/openRepoOnRemote.ts | 6 ++--- src/commands/showQuickCommitFile.ts | 4 ++-- src/commands/toggleFileAnnotations.ts | 4 +--- src/commands/toggleLineBlame.ts | 6 ++--- src/messages.ts | 38 ++++++++++++++++++++----------- 12 files changed, 48 insertions(+), 51 deletions(-) diff --git a/src/commands/copyCurrentBranch.ts b/src/commands/copyCurrentBranch.ts index da80a8a..c912e4d 100644 --- a/src/commands/copyCurrentBranch.ts +++ b/src/commands/copyCurrentBranch.ts @@ -1,9 +1,10 @@ import type { TextEditor, Uri } from 'vscode'; -import { env, window } from 'vscode'; +import { env } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; +import { showGenericErrorMessage } from '../messages'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; import { command } from '../system/command'; import { ActiveEditorCommand, getCommandUri } from './base'; @@ -29,7 +30,7 @@ export class CopyCurrentBranchCommand extends ActiveEditorCommand { } } catch (ex) { Logger.error(ex, 'CopyCurrentBranchCommand'); - void window.showErrorMessage('Unable to copy current branch name. See output channel for more details'); + void showGenericErrorMessage('Unable to copy current branch name'); } } } diff --git a/src/commands/openBranchOnRemote.ts b/src/commands/openBranchOnRemote.ts index cd41aae..4e7b743 100644 --- a/src/commands/openBranchOnRemote.ts +++ b/src/commands/openBranchOnRemote.ts @@ -1,10 +1,10 @@ import type { TextEditor, Uri } from 'vscode'; -import { window } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/models/remoteResource'; import { Logger } from '../logger'; +import { showGenericErrorMessage } from '../messages'; import { CommandQuickPickItem } from '../quickpicks/items/common'; import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks/referencePicker'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; @@ -87,9 +87,7 @@ export class OpenBranchOnRemoteCommand extends ActiveEditorCommand { })); } catch (ex) { Logger.error(ex, 'OpenBranchOnRemoteCommand'); - void window.showErrorMessage( - 'Unable to open branch on remote provider. See output channel for more details', - ); + void showGenericErrorMessage('Unable to open branch on remote provider'); } } } diff --git a/src/commands/openBranchesOnRemote.ts b/src/commands/openBranchesOnRemote.ts index 80341c9..aab92ec 100644 --- a/src/commands/openBranchesOnRemote.ts +++ b/src/commands/openBranchesOnRemote.ts @@ -1,10 +1,10 @@ import type { TextEditor, Uri } from 'vscode'; -import { window } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/models/remoteResource'; import { Logger } from '../logger'; +import { showGenericErrorMessage } from '../messages'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; import { command, executeCommand } from '../system/command'; import type { CommandContext } from './base'; @@ -63,9 +63,7 @@ export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand { })); } catch (ex) { Logger.error(ex, 'OpenBranchesOnRemoteCommand'); - void window.showErrorMessage( - 'Unable to open branches on remote provider. See output channel for more details', - ); + void showGenericErrorMessage('Unable to open branches on remote provider'); } } } diff --git a/src/commands/openCommitOnRemote.ts b/src/commands/openCommitOnRemote.ts index 9aa835d..fbed8a4 100644 --- a/src/commands/openCommitOnRemote.ts +++ b/src/commands/openCommitOnRemote.ts @@ -1,12 +1,11 @@ import type { TextEditor, Uri } from 'vscode'; -import { window } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitRevision } from '../git/models/reference'; import { RemoteResourceType } from '../git/models/remoteResource'; import { Logger } from '../logger'; -import { showFileNotUnderSourceControlWarningMessage } from '../messages'; +import { showFileNotUnderSourceControlWarningMessage, showGenericErrorMessage } from '../messages'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; import { command, executeCommand } from '../system/command'; import type { CommandContext } from './base'; @@ -106,9 +105,7 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand { })); } catch (ex) { Logger.error(ex, 'OpenCommitOnRemoteCommand'); - void window.showErrorMessage( - 'Unable to open commit on remote provider. See output channel for more details', - ); + void showGenericErrorMessage('Unable to open commit on remote provider'); } } } diff --git a/src/commands/openComparisonOnRemote.ts b/src/commands/openComparisonOnRemote.ts index 2fcff53..e83e7d7 100644 --- a/src/commands/openComparisonOnRemote.ts +++ b/src/commands/openComparisonOnRemote.ts @@ -1,8 +1,8 @@ -import { window } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { RemoteResourceType } from '../git/models/remoteResource'; import { Logger } from '../logger'; +import { showGenericErrorMessage } from '../messages'; import { command, executeCommand } from '../system/command'; import { ResultsCommitsNode } from '../views/nodes/resultsCommitsNode'; import type { CommandContext } from './base'; @@ -58,9 +58,7 @@ export class OpenComparisonOnRemoteCommand extends Command { })); } catch (ex) { Logger.error(ex, 'OpenComparisonOnRemoteCommand'); - void window.showErrorMessage( - 'Unable to open comparison on remote provider. See output channel for more details', - ); + void showGenericErrorMessage('Unable to open comparison on remote provider'); } } } diff --git a/src/commands/openCurrentBranchOnRemote.ts b/src/commands/openCurrentBranchOnRemote.ts index cb44c7f..878bb26 100644 --- a/src/commands/openCurrentBranchOnRemote.ts +++ b/src/commands/openCurrentBranchOnRemote.ts @@ -1,10 +1,10 @@ import type { TextEditor, Uri } from 'vscode'; -import { window } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/models/remoteResource'; import { Logger } from '../logger'; +import { showGenericErrorMessage } from '../messages'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; import { command, executeCommand } from '../system/command'; import { ActiveEditorCommand, getCommandUri } from './base'; @@ -37,9 +37,7 @@ export class OpenCurrentBranchOnRemoteCommand extends ActiveEditorCommand { } } catch (ex) { Logger.error(ex, 'OpenCurrentBranchOnRemoteCommand'); - void window.showErrorMessage( - 'Unable to open branch on remote provider. See output channel for more details', - ); + void showGenericErrorMessage('Unable to open branch on remote provider'); } } } diff --git a/src/commands/openFileOnRemote.ts b/src/commands/openFileOnRemote.ts index 28eace5..a8caf36 100644 --- a/src/commands/openFileOnRemote.ts +++ b/src/commands/openFileOnRemote.ts @@ -1,5 +1,5 @@ import type { TextEditor, Uri } from 'vscode'; -import { Range, window } from 'vscode'; +import { Range } from 'vscode'; import { UriComparer } from '../comparers'; import { BranchSorting, TagSorting } from '../configuration'; import { Commands, GlyphChars } from '../constants'; @@ -9,6 +9,7 @@ import { getBranchNameWithoutRemote, getRemoteNameFromBranchName } from '../git/ import { GitRevision } from '../git/models/reference'; import { RemoteResourceType } from '../git/models/remoteResource'; import { Logger } from '../logger'; +import { showGenericErrorMessage } from '../messages'; import { ReferencePicker } from '../quickpicks/referencePicker'; import { command, executeCommand } from '../system/command'; import { pad, splitSingle } from '../system/string'; @@ -206,7 +207,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand { })); } catch (ex) { Logger.error(ex, 'OpenFileOnRemoteCommand'); - void window.showErrorMessage('Unable to open file on remote provider. See output channel for more details'); + void showGenericErrorMessage('Unable to open file on remote provider'); } } } diff --git a/src/commands/openRepoOnRemote.ts b/src/commands/openRepoOnRemote.ts index 23daaaf..59e9104 100644 --- a/src/commands/openRepoOnRemote.ts +++ b/src/commands/openRepoOnRemote.ts @@ -1,10 +1,10 @@ import type { TextEditor, Uri } from 'vscode'; -import { window } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/models/remoteResource'; import { Logger } from '../logger'; +import { showGenericErrorMessage } from '../messages'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; import { command, executeCommand } from '../system/command'; import type { CommandContext } from './base'; @@ -61,9 +61,7 @@ export class OpenRepoOnRemoteCommand extends ActiveEditorCommand { })); } catch (ex) { Logger.error(ex, 'OpenRepoOnRemoteCommand'); - void window.showErrorMessage( - 'Unable to open repository on remote provider. See output channel for more details', - ); + void showGenericErrorMessage('Unable to open repository on remote provider'); } } } diff --git a/src/commands/showQuickCommitFile.ts b/src/commands/showQuickCommitFile.ts index 7e0493b..fbf3def 100644 --- a/src/commands/showQuickCommitFile.ts +++ b/src/commands/showQuickCommitFile.ts @@ -1,5 +1,5 @@ import type { TextEditor } from 'vscode'; -import { Uri, window } from 'vscode'; +import { Uri } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; @@ -100,7 +100,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand { args.commit = blame.commit; } catch (ex) { Logger.error(ex, 'ShowQuickCommitFileDetailsCommand', `getBlameForLine(${blameLine})`); - void window.showErrorMessage('Unable to show commit file details. See output channel for more details'); + void showGenericErrorMessage('Unable to show commit file details'); return; } diff --git a/src/commands/toggleFileAnnotations.ts b/src/commands/toggleFileAnnotations.ts index 0139c30..0c583b8 100644 --- a/src/commands/toggleFileAnnotations.ts +++ b/src/commands/toggleFileAnnotations.ts @@ -137,8 +137,6 @@ async function toggleFileAnnotations { if (commit == null) { @@ -44,20 +46,30 @@ export async function showDebugLoggingWarningMessage(): Promise { return result === disable; } -export async function showGenericErrorMessage(message: string): Promise { - const actions: MessageItem[] = [{ title: 'Open Output Channel' }]; - const result = await showMessage( - 'error', - `${message}. See output channel for more details`, - undefined, - null, - ...actions, - ); +export async function showGenericErrorMessage(message: string): Promise { + if (Logger.enabled(LogLevel.Error)) { + const result = await showMessage('error', `${message}. See output channel for more details.`, undefined, null, { + title: 'Open Output Channel', + }); - if (result !== undefined) { - Logger.showOutputChannel(); + if (result != null) { + Logger.showOutputChannel(); + } + } else { + const result = await showMessage( + 'error', + `${message}. If the error persists, please enable debug logging and try again.`, + undefined, + null, + { + title: 'Enable Debug Logging', + }, + ); + + if (result != null) { + void executeCommand(Commands.EnableDebugLogging); + } } - return result; } export function showFileNotUnderSourceControlWarningMessage(message: string): Promise {