Skip to content

Commit 36e6292

Browse files
committed
fix: improve error handling in embeddings and messages
Enhance error reporting by preserving original error message when embedding requests fail instead of generic error. Clean up error message format by removing all file:line prefixes for better readability.
1 parent 6cac01e commit 36e6292

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lua/CopilotChat/client.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ function Client:embed(inputs, model)
772772
while #to_process > 0 do
773773
local chunk_size = initial_chunk_size -- Reset chunk size for each new batch
774774
local threshold = BIG_EMBED_THRESHOLD -- Reset threshold for each new batch
775+
local last_error = nil
775776

776777
-- Take next chunk
777778
local batch = {}
@@ -788,6 +789,7 @@ function Client:embed(inputs, model)
788789

789790
if not ok then
790791
log.debug('Failed to get embeddings: ', data)
792+
last_error = data
791793
attempts = attempts + 1
792794
-- If we have few items and the request failed, try reducing threshold first
793795
if #batch <= 5 then
@@ -820,7 +822,7 @@ function Client:embed(inputs, model)
820822
end
821823

822824
if not success then
823-
error('Failed to process embeddings after multiple attempts')
825+
error(last_error)
824826
end
825827
end
826828

lua/CopilotChat/init.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ local function show_error(err, append_newline)
136136
err = err or 'Unknown error'
137137

138138
if type(err) == 'string' then
139-
local message = err:match('^[^:]+:[^:]+:(.+)') or err
140-
message = message:gsub('^%s*', '')
141-
err = message
139+
while true do
140+
local new_err = err:gsub('^[^:]+:%d+: ', '')
141+
if new_err == err then
142+
break
143+
end
144+
err = new_err
145+
end
142146
else
143147
err = utils.make_string(err)
144148
end

0 commit comments

Comments
 (0)