Refactors Logger.error to take the Error object

This commit is contained in:
Eric Amodio
2017-03-27 02:15:38 -04:00
parent c500293032
commit e0b3dcd484
31 changed files with 41 additions and 41 deletions

View File

@@ -63,7 +63,7 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
return undefined; return undefined;
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.CloseUnchangedFilesCommand]', ex); Logger.error(ex, 'CloseUnchangedFilesCommand');
return window.showErrorMessage(`Unable to close unchanged files. See output channel for more details`); return window.showErrorMessage(`Unable to close unchanged files. See output channel for more details`);
} }
} }

View File

@@ -50,7 +50,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
} }
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.CopyMessageToClipboardCommand]', `getBlameForLine(${blameline})`, ex); Logger.error(ex, 'CopyMessageToClipboardCommand', `getBlameForLine(${blameline})`);
return window.showErrorMessage(`Unable to copy message. See output channel for more details`); return window.showErrorMessage(`Unable to copy message. See output channel for more details`);
} }
} }
@@ -66,7 +66,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
return undefined; return undefined;
} }
catch (ex) { catch (ex) {
Logger.error('GitLens.CopyMessageToClipboardCommand', ex); Logger.error(ex, 'CopyMessageToClipboardCommand');
return window.showErrorMessage(`Unable to copy message. See output channel for more details`); return window.showErrorMessage(`Unable to copy message. See output channel for more details`);
} }
} }

View File

@@ -44,7 +44,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
sha = blame.commit.sha; sha = blame.commit.sha;
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.CopyShaToClipboardCommand]', `getBlameForLine(${blameline})`, ex); Logger.error(ex, 'CopyShaToClipboardCommand', `getBlameForLine(${blameline})`);
return window.showErrorMessage(`Unable to copy sha. See output channel for more details`); return window.showErrorMessage(`Unable to copy sha. See output channel for more details`);
} }
} }
@@ -53,7 +53,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
return undefined; return undefined;
} }
catch (ex) { catch (ex) {
Logger.error('GitLens.CopyShaToClipboardCommand', ex); Logger.error(ex, 'CopyShaToClipboardCommand');
return window.showErrorMessage(`Unable to copy sha. See output channel for more details`); return window.showErrorMessage(`Unable to copy sha. See output channel for more details`);
} }
} }

View File

@@ -40,7 +40,7 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
return undefined; return undefined;
} }
catch (ex) { catch (ex) {
Logger.error('GitLens.DiffDirectoryCommand', ex); Logger.error(ex, 'DiffDirectoryCommand');
return window.showErrorMessage(`Unable to open directory diff. See output channel for more details`); return window.showErrorMessage(`Unable to open directory diff. See output channel for more details`);
} }
} }

View File

@@ -49,7 +49,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
} }
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithPreviousLineCommand]', `getBlameForLine(${blameline})`, ex); Logger.error(ex, 'DiffWithPreviousLineCommand', `getBlameForLine(${blameline})`);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }
@@ -64,7 +64,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' }); return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithPreviousLineCommand]', 'getVersionedFile', ex); Logger.error(ex, 'DiffWithPreviousLineCommand', 'getVersionedFile');
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }

View File

@@ -39,7 +39,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
} }
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffLineWithWorkingCommand]', `getBlameForLine(${blameline})`, ex); Logger.error(ex, 'DiffLineWithWorkingCommand', `getBlameForLine(${blameline})`);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }

View File

@@ -40,7 +40,7 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' }); return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithBranchCommand]', 'getVersionedFile', ex); Logger.error(ex, 'DiffWithBranchCommand', 'getVersionedFile');
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }

View File

@@ -48,7 +48,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithNextCommand]', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`, ex); Logger.error(ex, 'DiffWithNextCommand', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }
@@ -66,7 +66,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' }); return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithNextCommand]', 'getVersionedFile', ex); Logger.error(ex, 'DiffWithNextCommand', 'getVersionedFile');
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }

View File

@@ -49,7 +49,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithPreviousCommand]', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`, ex); Logger.error(ex, 'DiffWithPreviousCommand', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }
@@ -68,7 +68,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' }); return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithPreviousCommand]', 'getVersionedFile', ex); Logger.error(ex, 'DiffWithPreviousCommand', 'getVersionedFile');
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }

View File

@@ -31,7 +31,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
if (!commit) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`); if (!commit) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithWorkingCommand]', `getLogCommit(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`, ex); Logger.error(ex, 'DiffWithWorkingCommand', `getLogCommit(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }
@@ -46,7 +46,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' }); return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.DiffWithWorkingCommand]', 'getVersionedFile', ex); Logger.error(ex, 'DiffWithWorkingCommand', 'getVersionedFile');
return window.showErrorMessage(`Unable to open diff. See output channel for more details`); return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
} }
} }

View File

@@ -134,7 +134,7 @@ export class Keyboard extends Disposable {
return await command.execute(); return await command.execute();
} }
catch (ex) { catch (ex) {
Logger.error('Keyboard.execute', ex); Logger.error(ex, 'Keyboard.execute');
return undefined; return undefined;
} }
} }

View File

@@ -34,7 +34,7 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand {
return undefined; return undefined;
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.OpenChangedFilesCommand]', ex); Logger.error(ex, 'OpenChangedFilesCommand');
return window.showErrorMessage(`Unable to open changed files. See output channel for more details`); return window.showErrorMessage(`Unable to open changed files. See output channel for more details`);
} }
} }

View File

@@ -39,7 +39,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
return commands.executeCommand(Commands.OpenInRemote, uri, remotes, 'commit', [commit.sha]); return commands.executeCommand(Commands.OpenInRemote, uri, remotes, 'commit', [commit.sha]);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.OpenCommitInRemoteCommand]', ex); Logger.error(ex, 'OpenCommitInRemoteCommand');
return window.showErrorMessage(`Unable to open commit in remote provider. See output channel for more details`); return window.showErrorMessage(`Unable to open commit in remote provider. See output channel for more details`);
} }
} }

View File

@@ -25,7 +25,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
return commands.executeCommand(Commands.OpenInRemote, uri, remotes, 'file', [gitUri.getRelativePath(), branch.name, gitUri.sha]); return commands.executeCommand(Commands.OpenInRemote, uri, remotes, 'file', [gitUri.getRelativePath(), branch.name, gitUri.sha]);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.OpenFileInRemoteCommand]', ex); Logger.error(ex, 'OpenFileInRemoteCommand');
return window.showErrorMessage(`Unable to open file in remote provider. See output channel for more details`); return window.showErrorMessage(`Unable to open file in remote provider. See output channel for more details`);
} }
} }

View File

@@ -47,7 +47,7 @@ export class OpenInRemoteCommand extends ActiveEditorCommand {
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.OpenInRemoteCommand]', ex); Logger.error(ex, 'OpenInRemoteCommand');
return window.showErrorMessage(`Unable to open in remote provider. See output channel for more details`); return window.showErrorMessage(`Unable to open in remote provider. See output channel for more details`);
} }
} }

View File

@@ -19,7 +19,7 @@ export class ShowBlameCommand extends EditorCommand {
return this.annotationController.showBlameAnnotation(editor, editor.selection.active.line); return this.annotationController.showBlameAnnotation(editor, editor.selection.active.line);
} }
catch (ex) { catch (ex) {
Logger.error('GitLens.ShowBlameCommand', ex); Logger.error(ex, 'ShowBlameCommand');
return window.showErrorMessage(`Unable to show blame annotations. See output channel for more details`); return window.showErrorMessage(`Unable to show blame annotations. See output channel for more details`);
} }
} }

View File

@@ -32,7 +32,7 @@ export class ShowBlameHistoryCommand extends EditorCommand {
return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations); return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowBlameHistoryCommand]', 'getBlameLocations', ex); Logger.error(ex, 'ShowBlameHistoryCommand', 'getBlameLocations');
return window.showErrorMessage(`Unable to show blame history. See output channel for more details`); return window.showErrorMessage(`Unable to show blame history. See output channel for more details`);
} }
} }

View File

@@ -31,7 +31,7 @@ export class ShowFileHistoryCommand extends EditorCommand {
return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations); return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowFileHistoryCommand]', 'getLogLocations', ex); Logger.error(ex, 'ShowFileHistoryCommand', 'getLogLocations');
return window.showErrorMessage(`Unable to show file history. See output channel for more details`); return window.showErrorMessage(`Unable to show file history. See output channel for more details`);
} }
} }

View File

@@ -17,7 +17,7 @@ export class ShowLastQuickPickCommand extends Command {
return commands.executeCommand(command.command, ...command.args); return commands.executeCommand(command.command, ...command.args);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowLastQuickPickCommand]', ex); Logger.error(ex, 'ShowLastQuickPickCommand');
return window.showErrorMessage(`Unable to show last quick pick. See output channel for more details`); return window.showErrorMessage(`Unable to show last quick pick. See output channel for more details`);
} }
} }

View File

@@ -65,7 +65,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
log); log);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickBranchHistoryCommand]', ex); Logger.error(ex, 'ShowQuickBranchHistoryCommand');
return window.showErrorMessage(`Unable to show branch history. See output channel for more details`); return window.showErrorMessage(`Unable to show branch history. See output channel for more details`);
} }
finally { finally {

View File

@@ -40,7 +40,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
commit = blame.commit; commit = blame.commit;
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickCommitDetailsCommand]', `getBlameForLine(${blameline})`, ex); Logger.error(ex, 'ShowQuickCommitDetailsCommand', `getBlameForLine(${blameline})`);
return window.showErrorMessage(`Unable to show commit details. See output channel for more details`); return window.showErrorMessage(`Unable to show commit details. See output channel for more details`);
} }
} }
@@ -91,7 +91,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
return commands.executeCommand(Commands.ShowQuickCommitFileDetails, pick.gitUri, pick.sha, undefined, currentCommand); return commands.executeCommand(Commands.ShowQuickCommitFileDetails, pick.gitUri, pick.sha, undefined, currentCommand);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickCommitDetailsCommand]', ex); Logger.error(ex, 'ShowQuickCommitDetailsCommand');
return window.showErrorMessage(`Unable to show commit details. See output channel for more details`); return window.showErrorMessage(`Unable to show commit details. See output channel for more details`);
} }
} }

View File

@@ -38,7 +38,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
workingFileName = path.relative(commit.repoPath, gitUri.fsPath); workingFileName = path.relative(commit.repoPath, gitUri.fsPath);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickCommitFileDetailsCommand]', `getBlameForLine(${blameline})`, ex); Logger.error(ex, 'ShowQuickCommitFileDetailsCommand', `getBlameForLine(${blameline})`);
return window.showErrorMessage(`Unable to show commit file details. See output channel for more details`); return window.showErrorMessage(`Unable to show commit file details. See output channel for more details`);
} }
} }
@@ -90,7 +90,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
return undefined; return undefined;
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickCommitFileDetailsCommand]', ex); Logger.error(ex, 'ShowQuickCommitFileDetailsCommand');
return window.showErrorMessage(`Unable to show commit file details. See output channel for more details`); return window.showErrorMessage(`Unable to show commit file details. See output channel for more details`);
} }
} }

View File

@@ -22,7 +22,7 @@ export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedComm
return commands.executeCommand(Commands.ShowQuickBranchHistory, uri, branch, undefined, goBackCommand); return commands.executeCommand(Commands.ShowQuickBranchHistory, uri, branch, undefined, goBackCommand);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickCurrentBranchHistoryCommand]', ex); Logger.error(ex, 'ShowQuickCurrentBranchHistoryCommand');
return window.showErrorMessage(`Unable to show branch history. See output channel for more details`); return window.showErrorMessage(`Unable to show branch history. See output channel for more details`);
} }
} }

View File

@@ -49,7 +49,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
log); log);
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'data.repoPath, ', ex); Logger.error(ex, 'ShowQuickFileHistoryCommand');
return window.showErrorMessage(`Unable to show file history. See output channel for more details`); return window.showErrorMessage(`Unable to show file history. See output channel for more details`);
} }
finally { finally {

View File

@@ -31,7 +31,7 @@ export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand {
} }
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.ShowQuickRepoStatusCommand]', ex); Logger.error(ex, 'ShowQuickRepoStatusCommand');
return window.showErrorMessage(`Unable to show repository status. See output channel for more details`); return window.showErrorMessage(`Unable to show repository status. See output channel for more details`);
} }
} }

View File

@@ -21,7 +21,7 @@ export class ToggleBlameCommand extends EditorCommand {
return this.annotationController.toggleBlameAnnotation(editor, editor.selection.active.line); return this.annotationController.toggleBlameAnnotation(editor, editor.selection.active.line);
} }
catch (ex) { catch (ex) {
Logger.error('GitLens.ToggleBlameCommand', ex); Logger.error(ex, 'ToggleBlameCommand');
return window.showErrorMessage(`Unable to show blame annotations. See output channel for more details`); return window.showErrorMessage(`Unable to show blame annotations. See output channel for more details`);
} }
} }

View File

@@ -48,7 +48,7 @@ export async function activate(context: ExtensionContext) {
repoPath = await Git.getRepoPath(rootPath, gitPath); repoPath = await Git.getRepoPath(rootPath, gitPath);
} }
catch (ex) { catch (ex) {
Logger.error(ex); Logger.error(ex, 'Extension.activate');
if (ex.message.includes('Unable to find git')) { if (ex.message.includes('Unable to find git')) {
await window.showErrorMessage(`GitLens was unable to find Git. Please make sure Git is installed. Also ensure that Git is either in the PATH, or that 'gitlens.advanced.git' is pointed to its installed location.`); await window.showErrorMessage(`GitLens was unable to find Git. Please make sure Git is installed. Also ensure that Git is either in the PATH, or that 'gitlens.advanced.git' is pointed to its installed location.`);
} }

View File

@@ -29,7 +29,7 @@ async function gitCommand(cwd: string, ...args: any[]) {
Logger.warn('git', ...args, ` cwd='${cwd}'`, msg && `\n ${msg.replace(/\r?\n|\r/g, ' ')}`); Logger.warn('git', ...args, ` cwd='${cwd}'`, msg && `\n ${msg.replace(/\r?\n|\r/g, ' ')}`);
} }
else { else {
Logger.error('git', ...args, ` cwd='${cwd}'`, msg && `\n ${msg.replace(/\r?\n|\r/g, ' ')}`); Logger.error(ex, 'git', ...args, ` cwd='${cwd}'`, msg && `\n ${msg.replace(/\r?\n|\r/g, ' ')}`);
} }
throw ex; throw ex;
} }

View File

@@ -25,7 +25,7 @@ export class RemoteProviderFactory {
return creator(domain, path); return creator(domain, path);
} }
catch (ex) { catch (ex) {
Logger.error(ex); Logger.error(ex, 'RemoteProviderFactory');
return undefined; return undefined;
} }
} }

View File

@@ -22,7 +22,7 @@ export class GitContentProvider implements TextDocumentContentProvider {
return text; return text;
} }
catch (ex) { catch (ex) {
Logger.error('[GitLens.GitContentProvider]', 'getVersionedFileText', ex); Logger.error(ex, 'GitContentProvider', 'getVersionedFileText');
await window.showErrorMessage(`Unable to show Git revision ${data.sha.substring(0, 8)} of '${path.relative(data.repoPath, fileName)}'`); await window.showErrorMessage(`Unable to show Git revision ${data.sha.substring(0, 8)} of '${path.relative(data.repoPath, fileName)}'`);
return undefined; return undefined;
} }

View File

@@ -50,13 +50,13 @@ export class Logger {
} }
} }
static error(message?: any, ...params: any[]): void { static error(ex: Error, classOrMethod?: string, ...params: any[]): void {
if (debug) { if (debug) {
console.error(ConsolePrefix, message, ...params); console.error(ConsolePrefix, ex, ...params);
} }
if (level !== OutputLevel.Silent) { if (level !== OutputLevel.Silent) {
output.appendLine([message, ...params].join(' ')); output.appendLine([ex, ...params].join(' '));
} }
} }