mini.nvim icon indicating copy to clipboard operation
mini.nvim copied to clipboard

Mini.Sessions fails to load session file at start if swap file warning printed

Open edshamis opened this issue 2 years ago • 5 comments

Contributing guidelines

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

edshamis avatar May 08 '22 10:05 edshamis

Thanks for the issue.

Does this error happen if you manually source session? Like with nvim -S <path-to-session>?

echasnovski avatar May 08 '22 10:05 echasnovski

This way E325 is printed but session loads without an error and vim.g.SessionLoad is nit

edshamis avatar May 08 '22 11:05 edshamis

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.

echasnovski avatar May 09 '22 14:05 echasnovski

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?

edshamis avatar May 09 '22 22:05 edshamis

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 :)

echasnovski avatar May 10 '22 12:05 echasnovski

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.

echasnovski avatar May 02 '23 15:05 echasnovski