From 55f97ef25741fa79096816252682e1e5502c8179 Mon Sep 17 00:00:00 2001 From: Yaohua-Leo <3067173925@qq.com> Date: Fri, 20 Mar 2026 10:00:01 +0800 Subject: [PATCH] fix(ollama): add try/catch to JSON.parse in buildAssistantMessage Responds to Greptile review feedback: add try/catch around JSON.parse in buildAssistantMessage to match extractToolCalls, preventing potential crash if Ollama returns malformed JSON string. --- src/agents/ollama-stream.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/agents/ollama-stream.ts b/src/agents/ollama-stream.ts index ccec6ea7d13..5e5cf9326c5 100644 --- a/src/agents/ollama-stream.ts +++ b/src/agents/ollama-stream.ts @@ -367,7 +367,13 @@ export function buildAssistantMessage( const rawArgs = tc.function.arguments; const normalizedArgs = typeof rawArgs === "string" - ? (JSON.parse(rawArgs) as Record) + ? (() => { + try { + return JSON.parse(rawArgs) as Record; + } catch { + return {} as Record; + } + })() : (rawArgs ?? {}); content.push({ type: "toolCall",