From 6b3572c858d1b5bb024b20fbbc2421563a340c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=82CHES?= Date: Tue, 17 Mar 2026 17:06:17 -0600 Subject: [PATCH] fix: add error handling for unhandled promise rejections (#992) Co-authored-by: Claude Opus 4.6 (1M context) --- src/resources/extensions/bg-shell/overlay.ts | 4 ++++ src/resources/extensions/gsd/auto-unit-closeout.ts | 4 +++- src/resources/extensions/gsd/files.ts | 4 +++- src/resources/extensions/gsd/guided-flow.ts | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/resources/extensions/bg-shell/overlay.ts b/src/resources/extensions/bg-shell/overlay.ts index 7c3599c1f..ddaf744bb 100644 --- a/src/resources/extensions/bg-shell/overlay.ts +++ b/src/resources/extensions/bg-shell/overlay.ts @@ -125,6 +125,10 @@ export class BgManagerOverlay { restartProcess(proc.id).then(() => { this.invalidate(); this.tui.requestRender(); + }).catch((err) => { + if (process.env.GSD_DEBUG) console.error('[bg-shell] restart failed:', err); + this.invalidate(); + this.tui.requestRender(); }); } return; diff --git a/src/resources/extensions/gsd/auto-unit-closeout.ts b/src/resources/extensions/gsd/auto-unit-closeout.ts index db902ce90..8d5bf4f94 100644 --- a/src/resources/extensions/gsd/auto-unit-closeout.ts +++ b/src/resources/extensions/gsd/auto-unit-closeout.ts @@ -37,7 +37,9 @@ export async function closeoutUnit( const { buildMemoryLLMCall, extractMemoriesFromUnit } = await import('./memory-extractor.js'); const llmCallFn = buildMemoryLLMCall(ctx); if (llmCallFn) { - extractMemoriesFromUnit(activityFile, unitType, unitId, llmCallFn).catch(() => {}); + extractMemoriesFromUnit(activityFile, unitType, unitId, llmCallFn).catch((err) => { + if (process.env.GSD_DEBUG) console.error(`[gsd] memory extraction failed for ${unitType}/${unitId}:`, err); + }); } } catch { /* non-fatal */ } } diff --git a/src/resources/extensions/gsd/files.ts b/src/resources/extensions/gsd/files.ts index 5a282b8c3..66099f1be 100644 --- a/src/resources/extensions/gsd/files.ts +++ b/src/resources/extensions/gsd/files.ts @@ -716,7 +716,9 @@ export async function saveFile(path: string, content: string): Promise { await fs.rename(tmpPath, path); } catch (err) { // Clean up orphaned temp file on rename failure - await fs.unlink(tmpPath).catch(() => {}); + await fs.unlink(tmpPath).catch((unlinkErr) => { + if (process.env.GSD_DEBUG) console.error(`[gsd] temp file cleanup failed for ${tmpPath}:`, unlinkErr); + }); throw err; } } diff --git a/src/resources/extensions/gsd/guided-flow.ts b/src/resources/extensions/gsd/guided-flow.ts index cb0b9416e..25d4a59c3 100644 --- a/src/resources/extensions/gsd/guided-flow.ts +++ b/src/resources/extensions/gsd/guided-flow.ts @@ -30,6 +30,7 @@ import { detectProjectState } from "./detection.js"; import { showProjectInit, offerMigration } from "./init-wizard.js"; import { showConfirm } from "../shared/confirm-ui.js"; import { loadQueueOrder, sortByQueueOrder, saveQueueOrder } from "./queue-order.js"; +import { debugLog } from "./debug-logger.js"; // ─── Commit Instruction Helpers ────────────────────────────────────────────── @@ -148,8 +149,9 @@ export function checkAutoStartAfterDiscuss(): boolean { pendingAutoStart = null; startAuto(ctx, pi, basePath, false, { step }).catch((err) => { - ctx.ui.notify(`Auto-start failed: ${err instanceof Error ? err.message : String(err)}`, "warning"); + ctx.ui.notify(`Auto-start failed: ${err instanceof Error ? err.message : String(err)}`, "error"); if (process.env.GSD_DEBUG) console.error('[gsd] auto start error:', err); + debugLog("auto-start-failed", { error: err instanceof Error ? err.message : String(err) }); }); return true; }