mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:10:45 +00:00
fix: cover plain streaming json parse failures
This commit is contained in:
@@ -483,6 +483,14 @@ describe("sanitizeUserFacingText — streaming JSON parse error (#59076)", () =>
|
||||
expect(result).toBe("LLM streaming response contained a malformed fragment. Please try again.");
|
||||
});
|
||||
|
||||
it.each([
|
||||
"Unexpected end of JSON input",
|
||||
"Unexpected non-whitespace character after JSON at position 4",
|
||||
])("rewrites plain JSON.parse error variants in error context: %s", (text) => {
|
||||
const result = sanitizeUserFacingText(text, { errorContext: true });
|
||||
expect(result).toBe("LLM streaming response contained a malformed fragment. Please try again.");
|
||||
});
|
||||
|
||||
it("does not rewrite JSON parse error when not in error context", () => {
|
||||
// When not in error context, the text could be legitimate assistant content
|
||||
// mentioning JSON errors. Don't rewrite.
|
||||
|
||||
@@ -19,6 +19,16 @@ describe("formatAssistantErrorText streaming JSON parse classification", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"Unexpected end of JSON input",
|
||||
"Unexpected non-whitespace character after JSON at position 4",
|
||||
])("suppresses plain JSON.parse streaming fragment failures: %s", (errorMessage) => {
|
||||
const msg = makeAssistantError(errorMessage);
|
||||
expect(formatAssistantErrorText(msg)).toBe(
|
||||
"LLM streaming response contained a malformed fragment. Please try again.",
|
||||
);
|
||||
});
|
||||
|
||||
it("suppresses structured Anthropic tool-call delta parse failures", () => {
|
||||
const msg = makeAssistantError(
|
||||
'Could not parse Anthropic SSE event content_block_delta: Unexpected end of JSON input; data={"type":"content_block_delta","delta":{"type":"input_json_delta","partial_json":"{\\"path\\":"},"index":0}',
|
||||
|
||||
@@ -223,7 +223,7 @@ export function isStreamingJsonParseError(raw: string): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
return /^(?:Expected (?:',' or '\}' after property value|double-quoted property name|':' after property name|',' or '\]' after array element)|Unterminated string) in JSON at position \d+(?: \(line \d+ column \d+\))?$/i.test(
|
||||
return /^(?:Unexpected end of JSON input|Unexpected non-whitespace character after JSON at position \d+(?: \(line \d+ column \d+\))?|(?:Expected (?:',' or '\}' after property value|double-quoted property name|':' after property name|',' or '\]' after array element)|Unterminated string) in JSON at position \d+(?: \(line \d+ column \d+\))?)$/i.test(
|
||||
trimmed,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user