From 6631b791ee3d647dc675d903f2684a7a79d1112c Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 8 Apr 2025 19:58:53 +0800 Subject: [PATCH] fix: tool input json parsing (#1834) --- lua/avante/llm_tools/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/avante/llm_tools/init.lua b/lua/avante/llm_tools/init.lua index eaea341..9faf166 100644 --- a/lua/avante/llm_tools/init.lua +++ b/lua/avante/llm_tools/init.lua @@ -1105,7 +1105,8 @@ function M.process_tool_use(tools, tool_use, on_log, on_complete, session_ctx) if tool == nil then return nil, "This tool is not provided: " .. tool_use.name end func = tool.func or M[tool.name] end - local input_json = vim.json.decode(tool_use.input_json) + local ok, input_json = pcall(vim.json.decode, tool_use.input_json) + if not ok then return nil, "Failed to decode tool input json: " .. vim.inspect(input_json) end if not func then return nil, "Tool not found: " .. tool_use.name end if on_log then on_log(tool_use.name, "running tool") end