From 1452c7233bb9c69f09173ab4d4e99a42106bf438 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 24 Jul 2025 17:37:10 +0800 Subject: [PATCH] fix: invalid json format (#2531) --- lua/avante/llm_tools/edit_file.lua | 2 +- lua/avante/providers/claude.lua | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/avante/llm_tools/edit_file.lua b/lua/avante/llm_tools/edit_file.lua index 595962e..728a25e 100644 --- a/lua/avante/llm_tools/edit_file.lua +++ b/lua/avante/llm_tools/edit_file.lua @@ -157,7 +157,7 @@ M.func = vim.schedule_wrap(function(input, opts) } local curl_cmd_str = table.concat(curl_cmd, " ") - local error_hint = curl_error_map[result.code] or "curl exited with code " .. result.code + local error_hint = curl_error_map[result.code] or ("curl exited with code " .. result.code) local full_error = "curl command failed: " .. error_hint .. "\n" diff --git a/lua/avante/providers/claude.lua b/lua/avante/providers/claude.lua index 26fb8ca..9d4e598 100644 --- a/lua/avante/providers/claude.lua +++ b/lua/avante/providers/claude.lua @@ -276,7 +276,11 @@ function M:parse_response(ctx, data_stream, event_state, opts) end elseif content_block.type == "tool_use" then if opts.on_messages_add then - local complete_json = vim.json.decode(content_block.input_json) + local ok_, complete_json = pcall(vim.json.decode, content_block.input_json) + if not ok_ then + Utils.warn("Failed to parse tool_use input_json: " .. content_block.input_json) + return + end local msg = new_assistant_message({ type = "tool_use", name = content_block.name,