elentok/format-on-save.nvim

Nvim fails to open temp file

pluiedev opened this issue · 2 comments

Formatting consistently fails with an error message like this for me:

Error detected while processing BufWritePre Autocommands for "*":
Error executing lua callback: Vim:E484: Can't open file /tmp/nvim.leah/5RM6OQ/3
stack traceback:
				[C]: in function 'readfile'
				...zy/format-on-save.nvim/lua/format-on-save/systemlist.lua:20: infunction 'systemlist'
				...m/lazy/format-on-save.nvim/lua/format-on-save/format.lua:128: in function 'format_with_shell'

After taking a look at the code, I don't exactly understand why it's failing to create a temporary file - I can do it just fine manually. Any insights?

Hi,

Thanks for raising this issue, It's strange, the vim.fn.filereadable() returns non-zero which means it expects the file to be readable but then vim.fn.readfile fails. Maybe filereadable isn't the proper way, I'm curious to look into this.

If you try to open the temp file manually (while the error message is still displayed), does it exist? what's the contents?

Also, what is your plugin configuration? which formatter is this?

Hi,

Thanks for raising this issue, It's strange, the vim.fn.filereadable() returns non-zero which means it expects the file to be readable but then vim.fn.readfile fails. Maybe filereadable isn't the proper way, I'm curious to look into this.

If you try to open the temp file manually (while the error message is still displayed), does it exist? what's the contents?

Also, what is your plugin configuration? which formatter is this?

Yeah this is weird... I'm trying to format Nix files with alejandra, and I couldn't find the temp file when tried to ls the temp folder. Maybe it's not creating the temp file at all?

Update: I tried to update the plugin via lazy.nvim and now it's no longer present. It might just be a problem with an older, faulty build of this plugin. I was going to say alejandra's behaving very strangely and printing messages to stderr even when it has successfully formatted the file, but I realized that was a me problem as I forgot to pass --quiet to it 🤦‍♀️ Everything should be working now