Skip to content

Commit 744182d

Browse files
ruslanfialkovskiiDavidyz
authored andcommitted
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.
1 parent af52fed commit 744182d

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

lua/vectorcode/integrations/codecompanion/common.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ 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.iter(t):flatten(math.huge):totable()
22+
local non_empty = vim.iter(flattened):filter(function(item)
23+
return type(item) == "string" and vim.trim(item) ~= ""
24+
end):totable()
25+
26+
if #non_empty == 0 then
27+
return "Unknown error occurred"
28+
end
29+
30+
return table.concat(non_empty, "\n")
2031
end,
2132

2233
---@param use_lsp boolean

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,21 @@ 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+
-- Check if this is actually an error or just empty stderr
467+
local is_actual_error = code ~= nil and code ~= 0
468+
local has_meaningful_error = false
469+
470+
if type(error) == "table" then
471+
-- Check if the error table contains any non-empty strings
472+
local flattened = vim.iter(error):flatten(math.huge):totable()
473+
has_meaningful_error = vim.iter(flattened):any(function(item)
474+
return type(item) == "string" and vim.trim(item) ~= ""
475+
end)
476+
elseif type(error) == "string" and vim.trim(error) ~= "" then
477+
has_meaningful_error = true
478+
end
479+
466480
if vim.islist(result) and #result > 0 and result[1].path ~= nil then ---@cast result VectorCode.QueryResult[]
467481
local summary_opts = vim.deepcopy(opts.summarise) or {}
468482
if type(summary_opts.enabled) == "function" then
@@ -496,13 +510,22 @@ return check_cli_wrap(function(opts)
496510
})
497511
end)
498512
else
499-
if type(error) == "table" then
500-
error = cc_common.flatten_table_to_string(error)
513+
-- Only report as error if we have a meaningful error or non-zero exit code
514+
if is_actual_error or has_meaningful_error then
515+
if type(error) == "table" then
516+
error = cc_common.flatten_table_to_string(error)
517+
end
518+
cb({
519+
status = "error",
520+
data = error or "VectorCode command failed",
521+
})
522+
else
523+
-- Successful operation but no results found
524+
cb({
525+
status = "success",
526+
data = { raw_results = {}, count = 0, summary = "" },
527+
})
501528
end
502-
cb({
503-
status = "error",
504-
data = error,
505-
})
506529
end
507530
end, tools.chat.bufnr)
508531
end,

0 commit comments

Comments
 (0)