Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ describe("runHook", () => {
expect(result?.stdout.trim()).toBe("claude-opus-4-6");
});

it("handles hook script failures gracefully", async () => {
it("throws when hook script fails", async () => {
const hooks: LifecycleHooks = { onCreate: "exit 1" };
const result = await runHook(hooks, "onCreate", {
...defaultCtx,
cwd: tmpDir,
});
// Should not throw, returns result with stderr
expect(result).not.toBeNull();
await expect(
runHook(hooks, "onCreate", {
...defaultCtx,
cwd: tmpDir,
}),
).rejects.toThrow("Hook onCreate failed:");
});

it("runs onComplete hook", async () => {
Expand Down
5 changes: 2 additions & 3 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ export async function runHook(
const result = await execAsync(script, {
cwd: ctx.cwd,
env,
timeout: 60_000,
timeout: 300_000,
});
return { stdout: result.stdout, stderr: result.stderr };
} catch (err) {
const e = err as Error & { stdout?: string; stderr?: string };
console.error(`Hook ${phase} failed:`, e.message);
return { stdout: e.stdout || "", stderr: e.stderr || "" };
throw new Error(`Hook ${phase} failed: ${e.message}`);
}
}