Skip to content

Commit 76bfba5

Browse files
committed
Show only error message from curl instead of whole object
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 683e07e commit 76bfba5

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

lua/CopilotChat/copilot.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ local curl_get = async.wrap(function(url, opts, callback)
5959
opts = vim.tbl_deep_extend('force', opts, {
6060
callback = callback,
6161
on_error = function(err)
62-
callback(nil, vim.inspect(err))
62+
err = err and err.stderr or vim.inspect(err)
63+
callback(nil, err)
6364
end,
6465
})
6566
curl.get(url, opts)
@@ -69,7 +70,8 @@ local curl_post = async.wrap(function(url, opts, callback)
6970
opts = vim.tbl_deep_extend('force', opts, {
7071
callback = callback,
7172
on_error = function(err)
72-
callback(nil, vim.inspect(err))
73+
err = err and err.stderr or vim.inspect(err)
74+
callback(nil, err)
7375
end,
7476
})
7577
curl.post(url, opts)

lua/CopilotChat/init.lua

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,32 @@ local function blend_color_with_neovim_bg(color_name, blend)
6060
return string.format('#%02x%02x%02x', r, g, b)
6161
end
6262

63+
local function dedupe_strings(str)
64+
if not str then
65+
return str
66+
end
67+
local seen = {}
68+
local result = {}
69+
for s in str:gmatch('[^%s,]+') do
70+
if not seen[s] then
71+
seen[s] = true
72+
table.insert(result, s)
73+
end
74+
end
75+
return table.concat(result, ' ')
76+
end
77+
78+
local function get_error_message(err)
79+
if type(err) == 'string' then
80+
-- Match first occurrence of :something: and capture rest
81+
local message = err:match('^[^:]+:[^:]+:(.+)') or err
82+
-- Trim whitespace
83+
message = message:match('^%s*(.-)%s*$')
84+
return dedupe_strings(message)
85+
end
86+
return dedupe_strings(vim.inspect(err))
87+
end
88+
6389
local function find_lines_between_separator(lines, pattern, at_least_one)
6490
local line_count = #lines
6591
local separator_line_start = 1
@@ -393,17 +419,6 @@ function M.ask(prompt, config, source)
393419
M.stop(true, config)
394420
end
395421

396-
local function get_error_message(err)
397-
if type(err) == 'string' then
398-
-- Match first occurrence of :something: and capture rest
399-
local message = err:match('^[^:]+:[^:]+:(.+)') or err
400-
-- Trim whitespace
401-
message = message:match('^%s*(.-)%s*$')
402-
return message
403-
end
404-
return vim.inspect(err)
405-
end
406-
407422
local function on_error(err)
408423
log.error(vim.inspect(err))
409424
vim.schedule(function()

0 commit comments

Comments
 (0)