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:
@@ -319,7 +319,9 @@ class ClaudeAgentSession implements AgentSession {
|
||||
}
|
||||
cancelIssued = true;
|
||||
this.turnCancelRequested = true;
|
||||
void this.interruptActiveTurn();
|
||||
this.interruptActiveTurn().catch((error) => {
|
||||
console.warn("[ClaudeAgentSession] Failed to interrupt during cancel:", error);
|
||||
});
|
||||
queue.end();
|
||||
};
|
||||
this.cancelCurrentTurn = requestCancel;
|
||||
@@ -330,7 +332,9 @@ class ClaudeAgentSession implements AgentSession {
|
||||
this.historyPending = false;
|
||||
this.persistedHistory = [];
|
||||
}
|
||||
void this.forwardPromptEvents(sdkMessage, queue);
|
||||
this.forwardPromptEvents(sdkMessage, queue).catch((error) => {
|
||||
console.error("[ClaudeAgentSession] Unexpected error in forwardPromptEvents:", error);
|
||||
});
|
||||
|
||||
try {
|
||||
for await (const event of queue) {
|
||||
|
||||
Reference in New Issue
Block a user