From bf39c83171f63ad21a17fced6bf65f381cd70787 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 15 Dec 2025 23:28:22 +0900 Subject: [PATCH] Fix: detect empty content messages in session-recovery error patterns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add pattern matching for 'content...is empty' format to detectErrorType function in session-recovery hook. This fixes detection of Anthropic API errors like 'The content field in the Message object at messages.65 is empty'. Previously only caught 'non-empty content' and 'must have non-empty content' patterns, missing this actual API error format. 🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/hooks/session-recovery/index.ts | 34 ++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/hooks/session-recovery/index.ts b/src/hooks/session-recovery/index.ts index fb37f8a..70cd0b1 100644 --- a/src/hooks/session-recovery/index.ts +++ b/src/hooks/session-recovery/index.ts @@ -50,12 +50,29 @@ interface MessagePart { function getErrorMessage(error: unknown): string { if (!error) return "" if (typeof error === "string") return error.toLowerCase() - const errorObj = error as { - data?: { message?: string } - message?: string - error?: { message?: string } + + const errorObj = error as Record + const paths = [ + errorObj.data, + errorObj.error, + errorObj, + (errorObj.data as Record)?.error, + ] + + for (const obj of paths) { + if (obj && typeof obj === "object") { + const msg = (obj as Record).message + if (typeof msg === "string" && msg.length > 0) { + return msg.toLowerCase() + } + } + } + + try { + return JSON.stringify(error).toLowerCase() + } catch { + return "" } - return (errorObj.data?.message || errorObj.error?.message || errorObj.message || "").toLowerCase() } function extractMessageIndex(error: unknown): number | null { @@ -85,7 +102,12 @@ function detectErrorType(error: unknown): RecoveryErrorType { return "thinking_disabled_violation" } - if (message.includes("non-empty content") || message.includes("must have non-empty content")) { + if ( + message.includes("non-empty content") || + message.includes("must have non-empty content") || + (message.includes("content") && message.includes("is empty")) || + (message.includes("content field") && message.includes("empty")) + ) { return "empty_content_message" }