Skip to content

Commit 9f480ef

Browse files
that-github-userunknownclaude
authored
Log warnings instead of silently swallowing git errors in getDiff/getDiffStats (#84)
Add console.warn with worktree path and error message when git commands fail, instead of empty catch blocks. Return values unchanged (empty diff/stats) so pipeline continues. 2 new tests verify warnings are emitted. Generated by thinktank (5 agents, 70% convergence, Agent #4 recommended). Closes #66 Co-authored-by: unknown <that-github-user@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0be06c1 commit 9f480ef

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/utils/git.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,37 @@ describe("cleanupBranches", () => {
5555
// Should not throw
5656
});
5757
});
58+
59+
describe("getDiff warning on failure", () => {
60+
it("warns to stderr and returns empty string for invalid worktree path", async () => {
61+
const warnings: string[] = [];
62+
const originalWarn = console.warn;
63+
console.warn = (...args: unknown[]) => warnings.push(args.join(" "));
64+
try {
65+
const result = await getDiff("/nonexistent/path/thinktank-test");
66+
assert.equal(result, "");
67+
assert.equal(warnings.length, 1);
68+
assert.ok(warnings[0].includes("getDiff failed"));
69+
assert.ok(warnings[0].includes("/nonexistent/path/thinktank-test"));
70+
} finally {
71+
console.warn = originalWarn;
72+
}
73+
});
74+
});
75+
76+
describe("getDiffStats warning on failure", () => {
77+
it("warns to stderr and returns empty stats for invalid worktree path", async () => {
78+
const warnings: string[] = [];
79+
const originalWarn = console.warn;
80+
console.warn = (...args: unknown[]) => warnings.push(args.join(" "));
81+
try {
82+
const result = await getDiffStats("/nonexistent/path/thinktank-test");
83+
assert.deepEqual(result, { filesChanged: [], linesAdded: 0, linesRemoved: 0 });
84+
assert.equal(warnings.length, 1);
85+
assert.ok(warnings[0].includes("getDiffStats failed"));
86+
assert.ok(warnings[0].includes("/nonexistent/path/thinktank-test"));
87+
} finally {
88+
console.warn = originalWarn;
89+
}
90+
});
91+
});

src/utils/git.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ export async function getDiff(worktreePath: string): Promise<string> {
4646
cwd: worktreePath,
4747
});
4848
return stdout;
49-
} catch {
49+
} catch (err) {
50+
console.warn(
51+
`[thinktank] getDiff failed for worktree ${worktreePath}: ${err instanceof Error ? err.message : String(err)}`,
52+
);
5053
return "";
5154
}
5255
}
@@ -76,7 +79,10 @@ export async function getDiffStats(
7679
}
7780

7881
return { filesChanged, linesAdded, linesRemoved };
79-
} catch {
82+
} catch (err) {
83+
console.warn(
84+
`[thinktank] getDiffStats failed for worktree ${worktreePath}: ${err instanceof Error ? err.message : String(err)}`,
85+
);
8086
return { filesChanged: [], linesAdded: 0, linesRemoved: 0 };
8187
}
8288
}

0 commit comments

Comments
 (0)