fix: gracefully handle missing input fields in hook handlers (#1098)
The summarize (Stop) and observation (PostToolUse) handlers throw blocking errors (exit code 2) when optional input fields like transcriptPath, toolName, or cwd are missing. This causes visible hook errors on every session stop and after some tool uses. Replace throws with graceful returns matching the existing pattern used for worker-unavailable checks. Fixes #1097 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,8 @@ export const observationHandler: EventHandler = {
|
||||
const { sessionId, cwd, toolName, toolInput, toolResponse } = input;
|
||||
|
||||
if (!toolName) {
|
||||
throw new Error('observationHandler requires toolName');
|
||||
// No tool name provided - skip observation gracefully
|
||||
return { continue: true, suppressOutput: true, exitCode: HOOK_EXIT_CODES.SUCCESS };
|
||||
}
|
||||
|
||||
const port = getWorkerPort();
|
||||
|
||||
@@ -29,7 +29,9 @@ export const summarizeHandler: EventHandler = {
|
||||
|
||||
// Validate required fields before processing
|
||||
if (!transcriptPath) {
|
||||
throw new Error(`Missing transcriptPath in Stop hook input for session ${sessionId}`);
|
||||
// No transcript available - skip summary gracefully (not an error)
|
||||
logger.debug('HOOK', `No transcriptPath in Stop hook input for session ${sessionId} - skipping summary`);
|
||||
return { continue: true, suppressOutput: true, exitCode: HOOK_EXIT_CODES.SUCCESS };
|
||||
}
|
||||
|
||||
// Extract last assistant message from transcript (the work Claude did)
|
||||
|
||||
Reference in New Issue
Block a user