Skip to content

Commit 5ac5502

Browse files
fix(codecompanion): improve error handling for empty stderr output (#286)
* fix(codecompanion): improve error handling for empty stderr output - Enhanced flatten_table_to_string to filter out empty error messages - Added logic to distinguish actual errors from empty stderr output - Prevents false error reporting when VectorCode operations succeed but have no stderr - Provides meaningful fallback error message for truly empty error conditions - Fixes issue where successful operations with empty stderr were reported as { "" } errors Resolves the confusing empty error message issue in CodeCompanion integration. * refactor(nvim): cleanup `flatten_table_to_string` * refactor(nvim): Simplify error handling in `query_tool` --------- Co-authored-by: Zhe Yu <[email protected]>
1 parent af52fed commit 5ac5502

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

lua/vectorcode/integrations/codecompanion/common.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ return {
1616
if type(t) == "string" then
1717
return t
1818
end
19-
return table.concat(vim.iter(t):flatten(math.huge):totable(), "\n")
19+
20+
-- Handle empty tables or tables with empty strings
21+
local flattened = vim
22+
.iter(t)
23+
:flatten(math.huge)
24+
:filter(function(item)
25+
return type(item) == "string" and vim.trim(item) ~= ""
26+
end)
27+
:totable()
28+
29+
if #flattened == 0 then
30+
return "Unknown error occurred"
31+
end
32+
33+
return table.concat(flattened, "\n")
2034
end,
2135

2236
---@param use_lsp boolean

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ return check_cli_wrap(function(opts)
462462
args
463463
)
464464

465-
job_runner.run_async(args, function(result, error)
465+
job_runner.run_async(args, function(result, error, code)
466+
local err_string = cc_common.flatten_table_to_string(error)
467+
466468
if vim.islist(result) and #result > 0 and result[1].path ~= nil then ---@cast result VectorCode.QueryResult[]
467469
local summary_opts = vim.deepcopy(opts.summarise) or {}
468470
if type(summary_opts.enabled) == "function" then
@@ -496,13 +498,20 @@ return check_cli_wrap(function(opts)
496498
})
497499
end)
498500
else
499-
if type(error) == "table" then
500-
error = cc_common.flatten_table_to_string(error)
501+
-- Only report as error if we have a meaningful error or non-zero exit code
502+
if (err_string and err_string ~= "") or code ~= 0 then
503+
cb({
504+
status = "error",
505+
data = ((err_string ~= "") and err_string)
506+
or "VectorCode query tool failed to execute.",
507+
})
508+
else
509+
-- Successful operation but no results found
510+
cb({
511+
status = "success",
512+
data = { raw_results = {}, count = 0 },
513+
})
501514
end
502-
cb({
503-
status = "error",
504-
data = error,
505-
})
506515
end
507516
end, tools.chat.bufnr)
508517
end,

0 commit comments

Comments
 (0)