Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 2565843

Browse files
committed
fix(generator): improve LLM response handling logic
- restructure response processing for clarity - handle error status with specific error messages - ensure callback is called for all response cases - add missing handler comment for LLM response
1 parent a134b04 commit 2565843

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

lua/codecompanion/_extensions/gitcommit/generator.lua

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Generate commit message for this diff:
106106
)
107107
end
108108

109+
---Handle LLM response
109110
---@param err table|nil Error from request
110111
---@param data table|nil Response data
111112
---@param adapter table The adapter used
@@ -122,25 +123,25 @@ function Generator._handle_response(err, data, adapter, callback)
122123
return callback(nil, "No response received from LLM")
123124
end
124125

125-
-- Process the LLM response
126-
local result = _adapter.handlers.chat_output(_adapter, data)
127-
if not (result and result.status) then
128-
return callback(nil, "No valid response received")
129-
end
130-
131-
if result.status == CONSTANTS.STATUS_SUCCESS then
132-
local content = result.output and result.output.content
133-
if content and vim.trim(content) ~= "" then
134-
return callback(vim.trim(content), nil)
135-
else
136-
return callback(nil, "Generated content is empty")
126+
-- Process successful response
127+
if data then
128+
local result = adapter.handlers.chat_output(adapter, data)
129+
if result and result.status then
130+
if result.status == CONSTANTS.STATUS_SUCCESS then
131+
local content = result.output and result.output.content
132+
if content and vim.trim(content) ~= "" then
133+
return callback(vim.trim(content), nil)
134+
else
135+
return callback(nil, "Generated content is empty")
136+
end
137+
elseif result.status == CONSTANTS.STATUS_ERROR then
138+
local error_msg = result.output or "Unknown error occurred"
139+
return callback(nil, error_msg)
140+
end
137141
end
138-
elseif result.status == CONSTANTS.STATUS_ERROR then
139-
local error_msg = result.output or "Unknown error occurred"
140-
return callback(nil, error_msg)
141-
else
142-
return callback(nil, "Unexpected response status: " .. tostring(result.status))
143142
end
143+
144+
return callback(nil, "No valid response received")
144145
end
145146

146147
return Generator

0 commit comments

Comments
 (0)