From e3df3b479f6469f3c0a82cd4939dbc198825079b Mon Sep 17 00:00:00 2001 From: Sayandip Dutta Date: Sun, 3 Nov 2024 14:14:12 +0530 Subject: [PATCH] fix(curl): show error when XDG_RUNTIME_DIR not writable (#785) --- lua/avante/llm.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index 21acddf..be14af7 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -1,5 +1,6 @@ local api = vim.api local fn = vim.fn +local uv = vim.uv local curl = require("plenary.curl") @@ -160,7 +161,25 @@ M.stream = function(opts) end end) end, - on_error = function() + on_error = function(err) + if err.exit == 23 then + local xdg_runtime_dir = os.getenv("XDG_RUNTIME_DIR") + if fn.isdirectory(xdg_runtime_dir) == 0 then + Utils.error( + "$XDG_RUNTIME_DIR=" + .. xdg_runtime_dir + .. " is set but does not exist. curl could not write output. Please make sure it exists, or unset.", + { title = "Avante" } + ) + elseif not uv.fs_access(xdg_runtime_dir, "w") then + Utils.error( + "$XDG_RUNTIME_DIR=" + .. xdg_runtime_dir + .. " exists but is not writable. curl could not write output. Please make sure it is writable, or unset.", + { title = "Avante" } + ) + end + end active_job = nil completed = true cleanup()