Skip to content

Commit 3fba4ab

Browse files
committed
refactor(nvim): Use fallback in flatten_table_to_string for empty error
1 parent 25ed507 commit 3fba4ab

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

lua/vectorcode/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function M.check(check_item, stdout_cb)
190190
if type(stdout_cb) == "function" then
191191
stdout_cb({
192192
stdout = utils.flatten_table_to_string(result),
193-
stderr = utils.flatten_table_to_string(error),
193+
stderr = utils.flatten_table_to_string(error, "Unknown error."),
194194
code = code,
195195
signal = signal,
196196
})

lua/vectorcode/integrations/codecompanion/files_ls_tool.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ return function(opts)
4343
cb({ status = "success", data = result })
4444
else
4545
if type(error) == "table" then
46-
error = utils.flatten_table_to_string(error)
46+
error = utils.flatten_table_to_string(error, "Unknown error.")
4747
end
4848
cb({
4949
status = "error",

lua/vectorcode/integrations/codecompanion/ls_tool.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ return function(opts)
4545
cb({ status = "success", data = result })
4646
else
4747
if type(error) == "table" then
48-
error = utils.flatten_table_to_string(error)
48+
error = utils.flatten_table_to_string(error, "Unknown error.")
4949
end
5050
cb({
5151
status = "error",

lua/vectorcode/integrations/codecompanion/prompts/init.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,12 @@ Here's my question:
131131
vc_config.notify_opts
132132
)
133133
elseif err ~= nil then
134-
err = utils.flatten_table_to_string(err)
135-
if err ~= "" then
136-
vim.schedule_wrap(vim.notify)(
137-
err,
138-
vim.log.levels.WARN,
139-
vc_config.notify_opts
140-
)
141-
end
134+
err = utils.flatten_table_to_string(err, "Unknown error.")
135+
vim.schedule_wrap(vim.notify)(
136+
err,
137+
vim.log.levels.WARN,
138+
vc_config.notify_opts
139+
)
142140
end
143141
end
144142
)

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
600600
vim.inspect(stderr)
601601
)
602602
)
603-
stderr = utils.flatten_table_to_string(stderr)
603+
stderr = utils.flatten_table_to_string(stderr, "Unknown error.")
604604
if string.find(stderr, "InvalidCollectionException") then
605605
if cmd.project_root then
606606
tools.chat:add_tool_output(

lua/vectorcode/integrations/codecompanion/vectorise_tool.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ The value should be one of the following:
125125
vim.inspect(stderr)
126126
)
127127
)
128-
stderr = utils.flatten_table_to_string(stderr)
128+
stderr = utils.flatten_table_to_string(stderr, "Unknown error.")
129129
tools.chat:add_tool_output(
130130
self,
131131
string.format("**VectorCode `vectorise` Tool: %s", stderr)

lua/vectorcode/utils.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ function M.is_directory(f)
174174
end
175175

176176
---@param t table|string|nil
177+
---@param fallback string?
177178
---@return string
178-
M.flatten_table_to_string = function(t)
179+
M.flatten_table_to_string = function(t, fallback)
180+
fallback = fallback or ""
179181
if t == nil then
180-
return ""
182+
return fallback
181183
end
182184
if type(t) == "string" then
183185
return t
@@ -193,7 +195,7 @@ M.flatten_table_to_string = function(t)
193195
:totable()
194196

195197
if #flattened == 0 then
196-
return "Unknown error occurred"
198+
return fallback
197199
end
198200

199201
return table.concat(flattened, "\n")

0 commit comments

Comments
 (0)