fix(gsd): handle deleted cwd in projectRoot to prevent ENOENT crash

process.cwd() throws ENOENT when the worktree directory was deleted
during a failed merge. Every /gsd command calls projectRoot(), causing
the entire extension to crash.

Now catches the ENOENT and falls back to HOME directory.

Closes #3598

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tibsfox 2026-04-06 19:12:48 -07:00
parent b4c6229360
commit 5cc2e24800

View file

@ -13,7 +13,13 @@ export interface GsdDispatchContext {
}
export function projectRoot(): string {
const cwd = process.cwd();
let cwd: string;
try {
cwd = process.cwd();
} catch {
// cwd directory was deleted (e.g. worktree teardown) — fall back to HOME (#3598)
cwd = process.env.HOME ?? "/";
}
const root = resolveProjectRoot(cwd);
if (root !== cwd) {
assertSafeDirectory(cwd);