fix: handle promise rejections in claude-agent fire-and-forget patterns

Fixed two fire-and-forget promise patterns that could cause unhandled rejections:
- interruptActiveTurn() in requestCancel closure - now catches errors and logs warning
- forwardPromptEvents() in stream method - now catches errors and logs to console

Both now properly handle promise rejections to prevent Node.js process crashes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-12-03 20:02:51 +07:00
co-authored by Claude
parent 2699e198d6
commit b7eed8409b
@@ -319,7 +319,9 @@ class ClaudeAgentSession implements AgentSession {
} }
cancelIssued = true; cancelIssued = true;
this.turnCancelRequested = true; this.turnCancelRequested = true;
void this.interruptActiveTurn(); this.interruptActiveTurn().catch((error) => {
console.warn("[ClaudeAgentSession] Failed to interrupt during cancel:", error);
});
queue.end(); queue.end();
}; };
this.cancelCurrentTurn = requestCancel; this.cancelCurrentTurn = requestCancel;
@@ -330,7 +332,9 @@ class ClaudeAgentSession implements AgentSession {
this.historyPending = false; this.historyPending = false;
this.persistedHistory = []; this.persistedHistory = [];
} }
void this.forwardPromptEvents(sdkMessage, queue); this.forwardPromptEvents(sdkMessage, queue).catch((error) => {
console.error("[ClaudeAgentSession] Unexpected error in forwardPromptEvents:", error);
});
try { try {
for await (const event of queue) { for await (const event of queue) {