From e0cf3358115ce292baf080d778f380d6ef9ab821 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 14 Sep 2016 02:28:20 -0400 Subject: [PATCH] Fixes #2 - Adds better error logging --- src/commands.ts | 14 +++++++++++--- src/extension.ts | 2 +- src/git.ts | 15 +++++++-------- src/gitProvider.ts | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 2c45dd5..81db4b2 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -47,6 +47,7 @@ export class DiffWithPreviousCommand extends EditorCommand { line = line || editor.selection.active.line; if (!sha) { return this.git.getBlameForLine(uri.fsPath, line) + .catch(ex => console.error('[GitLens.DiffWithPreviousCommand]', 'getBlameForLine', ex)) .then(blame => { if (!blame) return; @@ -64,6 +65,7 @@ export class DiffWithPreviousCommand extends EditorCommand { // TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line // which for a diff could be the first difference return Promise.all([this.git.getVersionedFile(uri.fsPath, sha), this.git.getVersionedFile(uri.fsPath, compareWithSha)]) + .catch(ex => console.error('[GitLens.DiffWithPreviousCommand]', 'getVersionedFile', ex)) .then(values => commands.executeCommand(BuiltInCommands.Diff, Uri.file(values[1]), Uri.file(values[0]), `${basename(compareWithUri.fsPath)} (${compareWithSha}) ↔ ${basename(shaUri.fsPath)} (${sha})`) .then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'}))); } @@ -78,6 +80,7 @@ export class DiffWithWorkingCommand extends EditorCommand { line = line || editor.selection.active.line; if (!sha) { return this.git.getBlameForLine(uri.fsPath, line) + .catch(ex => console.error('[GitLens.DiffWithWorkingCommand]', 'getBlameForLine', ex)) .then(blame => { if (!blame) return; @@ -91,6 +94,7 @@ export class DiffWithWorkingCommand extends EditorCommand { // TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line // which for a diff could be the first difference return this.git.getVersionedFile(shaUri.fsPath, sha) + .catch(ex => console.error('[GitLens.DiffWithWorkingCommand]', 'getVersionedFile', ex)) .then(compare => commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), uri, `${basename(shaUri.fsPath)} (${sha}) ↔ ${basename(uri.fsPath)} (index)`) .then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'}))); } @@ -108,6 +112,7 @@ export class ShowBlameCommand extends EditorCommand { const activeLine = editor.selection.active.line; return this.git.getBlameForLine(editor.document.fileName, activeLine) + .catch(ex => console.error('[GitLens.ShowBlameCommand]', 'getBlameForLine', ex)) .then(blame => this.blameController.showBlame(editor, blame && blame.commit.sha)); } } @@ -130,9 +135,11 @@ export class ShowBlameHistoryCommand extends EditorCommand { if (!uri) return; } - return this.git.getBlameLocations(uri.fsPath, range).then(locations => { - return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations); - }); + return this.git.getBlameLocations(uri.fsPath, range) + .catch(ex => console.error('[GitLens.ShowBlameHistoryCommand]', 'getBlameLocations', ex)) + .then(locations => { + return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations); + }); } } @@ -148,6 +155,7 @@ export class ToggleBlameCommand extends EditorCommand { const activeLine = editor.selection.active.line; return this.git.getBlameForLine(editor.document.fileName, activeLine) + .catch(ex => console.error('[GitLens.ToggleBlameCommand]', 'getBlameForLine', ex)) .then(blame => this.blameController.toggleBlame(editor, blame && blame.commit.sha)); } } \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 455fefa..9aaa6ec 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -39,7 +39,7 @@ export function activate(context: ExtensionContext) { context.subscriptions.push(new ShowBlameCommand(git, blameController)); context.subscriptions.push(new ToggleBlameCommand(git, blameController)); context.subscriptions.push(new ShowBlameHistoryCommand(git)); - }).catch(reason => console.warn(reason)); + }).catch(reason => console.warn('[GitLens]', reason)); } // this method is called when your extension is deactivated diff --git a/src/git.ts b/src/git.ts index e062131..29856d4 100644 --- a/src/git.ts +++ b/src/git.ts @@ -5,8 +5,13 @@ import * as tmp from 'tmp'; import {spawnPromise} from 'spawn-rx'; function gitCommand(cwd: string, ...args) { - console.log('git', ...args); - return spawnPromise('git', args, { cwd: cwd }); + console.log('[GitLens]', 'git', ...args); + return spawnPromise('git', args, { cwd: cwd }) + // .then(s => { console.log('[GitLens]', s); return s; }) + .catch(ex => { + console.error('[GitLens]', 'git', ...args, 'Failed:', ex); + throw ex; + }); } export default class Git { @@ -26,8 +31,6 @@ export default class Git { } return gitCommand(repoPath, 'blame', '-fn', '--root', '--', fileName); - // .then(s => { console.log(s); return s; }) - // .catch(ex => console.error(ex)); } static blamePorcelain(fileName: string, repoPath: string, sha?: string) { @@ -38,8 +41,6 @@ export default class Git { } return gitCommand(repoPath, 'blame', '--porcelain', '--root', '--', fileName); - // .then(s => { console.log(s); return s; }) - // .catch(ex => console.error(ex)); } static getVersionedFile(fileName: string, repoPath: string, sha: string) { @@ -70,8 +71,6 @@ export default class Git { sha = sha.replace('^', ''); return gitCommand(repoPath, 'show', `${sha}:${fileName}`); - // .then(s => { console.log(s); return s; }) - // .catch(ex => console.error(ex)); } // static getCommitMessage(sha: string, repoPath: string) { diff --git a/src/gitProvider.ts b/src/gitProvider.ts index 48caeda..053f69f 100644 --- a/src/gitProvider.ts +++ b/src/gitProvider.ts @@ -57,7 +57,7 @@ export default class GitProvider extends Disposable { reset = !!reset; if (this._blames.delete(fileName.toLowerCase())) { - console.log(`GitProvider._clearBlame(${fileName}, ${reset})`); + console.log('[GitLens]', `Clear blame cache: fileName=${fileName}, reset=${reset})`); if (reset) { // TODO: Killing the code lens provider is too drastic -- makes the editor jump around, need to figure out how to trigger a refresh