fix: gracefully handle failed curl (#2356)

This commit is contained in:
Peter Cardenas
2025-06-28 05:10:27 -07:00
committed by GitHub
parent 7f25a33dbb
commit 87f3aee073

View File

@@ -477,7 +477,7 @@ function M.curl(opts)
local completed = false local completed = false
local active_job local active_job ---@type Job|nil
local temp_file = fn.tempname() local temp_file = fn.tempname()
local curl_body_file = temp_file .. "-request-body.json" local curl_body_file = temp_file .. "-request-body.json"
@@ -501,7 +501,7 @@ function M.curl(opts)
local headers_reported = false local headers_reported = false
active_job = curl.post(spec.url, { local started_job, new_active_job = pcall(curl.post, spec.url, {
headers = spec.headers, headers = spec.headers,
proxy = spec.proxy, proxy = spec.proxy,
insecure = spec.insecure, insecure = spec.insecure,
@@ -618,6 +618,14 @@ function M.curl(opts)
end, end,
}) })
if not started_job then
local error_msg = vim.inspect(new_active_job)
Utils.error("Failed to make LLM request: " .. error_msg)
handler_opts.on_stop({ reason = "error", error = error_msg })
return
end
active_job = new_active_job
api.nvim_create_autocmd("User", { api.nvim_create_autocmd("User", {
group = group, group = group,
pattern = M.CANCEL_PATTERN, pattern = M.CANCEL_PATTERN,