bug: sliently ignoring curl failure if XDG_RUNTIME_DIR is not writable
sayandipdutta opened this issue · 4 comments
Describe the bug
As noted in #775 for any message, avante
shows generation complete, please view response above. No amount of reinstalling, clearing saved data, changing neovim version helped.
I dug a bit deeper and found out curl was bailing out with exit code 23
, i.e. it was unable to write response in temp file. It turns out curl checks whether XDG_RUNTIME_DIR is set, if it is, it tries to write data there, if not, only then it goes to /tmp
(see nvim-lua/plenary.nvim#536 (comment)). In my case, I had turned off systemd
because of some issue I was facing with WSL+Ubuntu 22.04+, but XDG_RUNTIME_DIR
was set on my .zshrc
. But since there was no systeminit daemon, the /run/user/$UID
was not getting created. Furthermore, forcibly creating XDG_RUNTIME_DIR
is not enough, it should be owned by the user, i.e. it should be writable.
To reproduce
Try removing XDG_RUNTIME_DIR
(at your own risk 😄 ) I'd recommend taking a backup of the directory first, so it can be restored.
$ if [ -z $XDG_RUNTIME_DIR ]; then
export XDG_RUNTIME_DIR=/run/user/$UID
sudo rm -rf $XDG_RUNTIME_DIR
fi
$
Open neovim, launch AvanteAsk
and put in any message, you should be able to reproduce #775 .
Expected behavior
When XDG_RUNTIME_DIR
is not writable, curl
will inevitably fail. In fact, avante.nvim
should not try to set XDG_RUNTIME_DIR
on the fly, because that may have other concerns. But the user should be notified with a descriptive error message should be raised so that they can take action if possible.
Installation method
Use lazy.nvim:
return {
"yetone/avante.nvim",
event = "VeryLazy",
lazy = false,
opts = {
provider = "claude",
},
build = "make",
keys = {
{
"<leader>aa",
function()
require("avante.api").ask()
end,
desc = "avante: ask",
mode = { "n", "v" },
},
{
"<leader>ar",
function()
require("avante.api").refresh()
end,
desc = "avante: refresh",
},
{
"<leader>ae",
function()
require("avante.api").edit()
end,
desc = "avante: edit",
mode = "v",
},
},
dependencies = {
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
--- The below dependencies are optional,
"nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
{
-- support for image pasting
"HakonHarnes/img-clip.nvim",
event = "VeryLazy",
opts = {
-- recommended settings
default = {
embed_image_as_base64 = false,
prompt_for_file_name = false,
drag_and_drop = {
insert_mode = true,
},
-- required for Windows users
use_absolute_path = true,
},
},
},
{
-- Make sure to setup it properly if you have lazy=true
"MeanderingProgrammer/render-markdown.nvim",
opts = {
file_types = { "markdown", "Avante" },
},
ft = { "markdown", "Avante" },
},
},
}
Environment
neovim version: 0.10.2
platform: Ubuntu 24.04 On WSL2 on Windows 11
Repro
No response
There are a few workarounds:
Option 1. If XDG_RUNTIME_DIR
does not exist, unset XDG_RUNTIME_DIR
(do this only if you know nothing else will break)
$ unset XDG_RUNTIME_DIR=/run/user/$UID
then curl will write in /tmp
Option 2. Create XDG_RUNTIME_DIR
and own it.
$ sudo mkdir -p $XDG_RUNTIME_DIR
$ sudo chown -R <username> $XDG_RUNTIME_DIR
Option 3. If you expect XDG_RUNTIME_DIR to exist, investigate why it doesn't in the first place.
Ah! I just found #315 , and if the wiki entry was a little more prominent I wouldn't have to pull my hairs out. Still I think silently ignoring this is problematic, and had it showed the exit code 23
message instead of ignoring it, I would have found the issue earlier. So I will still keep my PR (#785) open.
For others, the aboslute last line in the wiki suggests:
WSL
Try set XDG_RUNTIME_DIR="/tmp/"
This solution fixed it for me! Thank you so much.
handled in #785