fix: handle missing assistant messages gracefully in transcript parser
When a user exits Claude Code before any assistant response is generated, the summarize Stop hook would crash with: "No message found for role 'assistant' in transcript" This happened because extractLastMessage() threw an error when no message of the requested role was found. The fix returns an empty string instead, which the summarize handler already handles gracefully (it logs hasLastAssistantMessage: false and continues). This is consistent with the function's existing behavior - it already returns '' in other edge cases (line 64). Fixes sessions that exit early before assistant responds. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Alex Newman
parent
40e699209f
commit
75df2e52c1
@@ -58,7 +58,7 @@ export function extractLastMessage(
|
||||
|
||||
// If we searched the whole transcript and didn't find any message of this role
|
||||
if (!foundMatchingRole) {
|
||||
throw new Error(`No message found for role '${role}' in transcript: ${transcriptPath}`);
|
||||
return '';
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user