mini.nvim
mini.nvim copied to clipboard
Mini.Sessions fails to load session file at start if swap file warning printed
Contributing guidelines
- [X] I have read CONTRIBUTING.md
- [X] I have read CODE_OF_CONDUCT.md
- [X] I have updated 'mini.nvim' to latest version
Module(s)
mini.sessions
Description
More precisely, session script load is interrupted after the E325 (swap file warning) is printed. vim.g.SessionLoad remains 1
Neovim version
v0.8.0-dev+133
Steps to reproduce
require('mini.sessions').setup({ autoread = true, autowrite = true, directory = '~/.config/nvim/sessions/', file = 'session.vim', force = { read = false, write = true, delete = false }, verbose = { read = true, write = true, delete = true }, })
Expected behavior
No response
Actual behavior
Error detected while processing VimEnter Autocommands for "*": E5108: Error executing lua ...local/share/nvim/plugged/mini.nvim/lua/mini/sessions.lua:194: Vim(edit):E325: ATTENTION stack traceback: [C]: in function 'cmd' ...local/share/nvim/plugged/mini.nvim/lua/mini/sessions.lua:194: in function 'read' ...local/share/nvim/plugged/mini.nvim/lua/mini/sessions.lua:399: in function 'on_vimenter' [string ":lua"]:1: in main chunk
Thanks for the issue.
Does this error happen if you manually source session? Like with nvim -S <path-to-session>
?
This way E325 is printed but session loads without an error and vim.g.SessionLoad is nit
So after investigation, this happens because I couldn't find a way to fully emulate Vimscript's :source
through Lua. And I don't think it even exists at the moment. The current vim.cmd('source ... ')
emulates :source
fine in case of no errors, but differs if some command throws error.
I've opened neovim/neovim#18497 to see what can be done. Otherwise, I don't think I can do much within plugin itself.
I see, thanks for the explanation. As I understand in such case of an error at startup the session script is interrupted but mimi.sessions still thinks it has read the session file and keeps managing it. Maybe it can at least disable itself (with a notification) if it can be aware of an error?
As I understand in such case of an error at startup the session script is interrupted but mimi.sessions still thinks it has read the session file and keeps managing it.
Correct.
I am currently thinking about how to best approach this problem. The best way is to use some native nvim_source
from issue I've created earlier (or other comparable approach I've missed). Otherwise, not sure what "disable itself" would mean here, but some kind of reaction to error would be appropriate.
Something should be done with error handling here, that is for sure. Yet not sure what exactly :)
I stand hugely corrected. Although upstream Neovim does have inconsistency for error handling, there was a simple one-word solution to the problem: use silent! source
instead of source
to read session.
As far as I can tell, this should be solved on latest main
.