Skip to content

Commit

Permalink
Fixes error logging scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Aug 31, 2023
1 parent 9b0305d commit 1bd6a17
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/env/node/git/localGitProvider.ts
Expand Up @@ -1162,6 +1162,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
repoPath: string,
options?: { all?: boolean; branch?: GitBranchReference; prune?: boolean; pull?: boolean; remote?: string },
): Promise<void> {
const scope = getLogScope();

const { branch, ...opts } = options ?? {};
try {
if (isBranchReference(branch)) {
Expand All @@ -1180,7 +1182,7 @@ export class LocalGitProvider implements GitProvider, Disposable {

this.container.events.fire('git:cache:reset', { repoPath: repoPath });
} catch (ex) {
Logger.error(ex, 'LocalGitProvider.fetch');
Logger.error(ex, scope);
if (FetchError.is(ex)) {
void window.showErrorMessage(ex.message);
} else {
Expand All @@ -1195,6 +1197,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
repoPath: string,
options?: { branch?: GitBranchReference; force?: boolean; publish?: { remote: string } },
): Promise<void> {
const scope = getLogScope();

let branch = options?.branch;
if (!isBranchReference(branch)) {
branch = await this.getBranch(repoPath);
Expand All @@ -1217,7 +1221,7 @@ export class LocalGitProvider implements GitProvider, Disposable {

this.container.events.fire('git:cache:reset', { repoPath: repoPath });
} catch (ex) {
Logger.error(ex, 'LocalGitProvider.push');
Logger.error(ex, scope);
if (PushError.is(ex)) {
void window.showErrorMessage(ex.message);
} else {
Expand All @@ -1232,6 +1236,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
repoPath: string,
options?: { branch?: GitBranchReference; rebase?: boolean; tags?: boolean },
): Promise<void> {
const scope = getLogScope();

let branch = options?.branch;
if (!isBranchReference(branch)) {
branch = await this.getBranch(repoPath);
Expand All @@ -1251,7 +1257,7 @@ export class LocalGitProvider implements GitProvider, Disposable {

this.container.events.fire('git:cache:reset', { repoPath: repoPath });
} catch (ex) {
Logger.error(ex, 'LocalGitProvider.pull');
Logger.error(ex, scope);
if (PullError.is(ex)) {
void window.showErrorMessage(ex.message);
} else {
Expand Down Expand Up @@ -4101,6 +4107,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
async getRemotes(repoPath: string | undefined, options?: { sort?: boolean }): Promise<GitRemote[]> {
if (repoPath == null) return [];
const scope = getLogScope();
let remotesPromise = this.useCaching ? this._remotesCache.get(repoPath) : undefined;
if (remotesPromise == null) {
async function load(this: LocalGitProvider): Promise<GitRemote[]> {
Expand All @@ -4120,7 +4128,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return remotes;
} catch (ex) {
this._remotesCache.delete(repoPath!);
Logger.error(ex);
Logger.error(ex, scope);
return [];
}
}
Expand Down Expand Up @@ -4458,6 +4466,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
): Promise<[string, string] | undefined> {
if (ref === deletedOrMissing) return undefined;
const scope = getLogScope();
try {
while (true) {
if (!repoPath) {
Expand Down Expand Up @@ -4518,7 +4528,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return [relativePath, repoPath];
}
} catch (ex) {
Logger.error(ex);
Logger.error(ex, scope);
return undefined;
}
}
Expand All @@ -4537,6 +4547,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
uri: Uri,
options?: { ref1?: string; ref2?: string; staged?: boolean; tool?: string },
): Promise<void> {
const scope = getLogScope();
const [relativePath, root] = splitPath(uri, repoPath);
try {
Expand Down Expand Up @@ -4568,13 +4579,15 @@ export class LocalGitProvider implements GitProvider, Disposable {
return;
}
Logger.error(ex, 'openDiffTool');
Logger.error(ex, scope);
void showGenericErrorMessage('Unable to open compare');
}
}
@log()
async openDirectoryCompare(repoPath: string, ref1: string, ref2?: string, tool?: string): Promise<void> {
const scope = getLogScope();
try {
if (!tool) {
const scope = getLogScope();
Expand Down Expand Up @@ -4603,7 +4616,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return;
}
Logger.error(ex, 'openDirectoryCompare');
Logger.error(ex, scope);
void showGenericErrorMessage('Unable to open directory compare');
}
}
Expand Down Expand Up @@ -5080,13 +5093,15 @@ export class LocalGitProvider implements GitProvider, Disposable {
path: string,
options?: { commitish?: string; createBranch?: string; detach?: boolean; force?: boolean },
) {
const scope = getLogScope();
try {
await this.git.worktree__add(repoPath, path, options);
if (options?.createBranch) {
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['branches'] });
}
} catch (ex) {
Logger.error(ex);
Logger.error(ex, scope);
const msg = String(ex);
Expand Down Expand Up @@ -5137,6 +5152,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
@log()
async deleteWorktree(repoPath: string, path: string, options?: { force?: boolean }) {
const scope = getLogScope();
await this.ensureGitVersion(
'2.17.0',
'Deleting worktrees',
Expand All @@ -5146,7 +5163,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
try {
await this.git.worktree__remove(repoPath, path, options);
} catch (ex) {
Logger.error(ex);
Logger.error(ex, scope);
const msg = String(ex);
Expand Down

0 comments on commit 1bd6a17

Please sign in to comment.