auto-session
auto-session copied to clipboard
[BUG] auto-session seems to always display an error on home directory
Describe Bug With auto-save and auto-load enabled, the plugin behaves as expected in all directories; automatically saving the session when NeoVim is closed and loading the session when reopened. But this expected behavior fails when the working directory is $HOME. NeoVim displays errors before startup is complete and disables autosave for that session.
Steps To Reproduce
- Enable the auto-save and auto-load options for
auto-session
. - Open $HOME directory in NeoVim, do some work and close the session.
- Reopen $HOME directory again.
- The error (shown below in screenshot) should appear on the screen before NeoVim starts up fully.
Expected Behavior The session should load automatically without any errors displayed.
Screenshot
System Information
- Session Options :
buffers,curdir,folds,help,localoptions,options,tabpages,terminal,winsize
- OS :
Linux Tensei 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
- Neovim version :
NVIM v0.9.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-oiekze/neovim-0.9.0~ubuntu1+git202301230018-e5a537c88-333b5866f=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fno-common -fdiagnostics-color=auto -fstack-protector-strong -DNVIM_UNIBI_HAS_VAR_FROM -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DMIN_LOG_LEVEL=3 -I/usr/include/luajit-2.1 -I/usr/include -I/build/neovim-oiekze/neovim-0.9.0~ubuntu1+git202301230018-e5a537c88-333b5866f/.deps/usr/include -I/build/neovim-oiekze/neovim-0.9.0~ubuntu1+git202301230018-e5a537c88-333b5866f/build/src/nvim/auto -I/build/neovim-oiekze/neovim-0.9.0~ubuntu1+git202301230018-e5a537c88-333b5866f/build/include -I/build/neovim-oiekze/neovim-0.9.0~ubuntu1+git202301230018-e5a537c88-333b5866f/build/cmake.config -I/build/neovim-oiekze/neovim-0.9.0~ubuntu1+git202301230018-e5a537c88-333b5866f/src
Compiled by buildd@lcy02-amd64-048
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info
- URL to your current config : dasupradyumna/neovim-config
It is unlikely this would have anything to do with what directory you're trying to load. By the look of it, you're trying to lazyload auto-session, this is not recommended. The link to your config is hitting 404, so I can't tell for sure that's the case.
I get the same error. Here is my config https://github.com/Johannesklint/dotfiles/blob/main/nvim/.config/nvim/lua/primalivet/packer.lua#L66
Hey, I'm sorry for the tardy response. Please check the link to my config now, it should work. And I double-checked my config as per your suggestion. I also use your "session-lens" plugin, but neither plugin is lazy-loaded.
Hey @Johannesklint what happens if you remove ~/
from auto_session_suppress_dirs
? Do you still get an error?
Hey @Johannesklint what happens if you remove
~/
fromauto_session_suppress_dirs
? Do you still get an error?
I have tried that, still getting the same error unfortunately. When running :PackerSync
I get this output: ✗ Failed to update rmagatti/auto-session
Hey @Johannesklint what happens if you remove
~/
fromauto_session_suppress_dirs
? Do you still get an error?
I also added that to my config as a bandaid, after creating this issue. This prevents the error in my case, but I lose "auto-session" capabilities in the $HOME directory. :(
Okay so I've looked a bit deeper into this, this SessionLoad
call happens in Neovim itself. I can't really reproduce here but to confirm you can try:
- Deleting your current nome dir session, by running
:DeleteSession
after opening Neovim at the home dir - Manually create a session with
:mksess
- Close Neovim
- Open Neovim
- Try loading the session
:source Session.vim
You should see the same error even without auto-session involvement.
After following your steps it now works...
Okay so I've looked a bit deeper into this, this
SessionLoad
call happens in Neovim itself. I can't really reproduce here but to confirm you can try:
- Deleting your current nome dir session, by running
:DeleteSession
after opening Neovim at the home dir- Manually create a session with
:mksess
- Close Neovim
- Open Neovim
- Try loading the session
:source Session.vim
You should see the same error even without auto-session involvement.
After following those steps it works! Thanks
🤔 Those steps shouldn't have made anything work, there might be something else at play here
That's what's weird. It created a file called Session.vim where tabs and such is stored in a cached session. I guess that's why it now works... 🤔
I have the same problem. After set restore_upcoming_session = false
, that error won't show up anymore. But somehow if I open a file from other project's directory (nvimtree will auto change cwd to that project root), it will close all the buffers from old project.
from this commit i got error: 04ccdac802200ecc363b251cf922b2b022bb515c
{
"rmagatti/auto-session",
commit = "04ccdac802200ecc363b251cf922b2b022bb515c",
lazy = false,
config = function()
require("auto-session").setup({
log_level = "debug",
auto_session_enabled = true,
auto_session_create_enabled = true,
auto_save_enabled = true,
auto_restore_enabled = true,
auto_session_enable_last_session = true,
auto_session_allowed_dirs = { "~/git/*" },
cwd_change_handling = {
restore_upcoming_session = false,
},
})
end,
},
But if I use this commit c8b2f4048f846387361bd04cc185bf1aa7d2e3d1 auto save last session
and auto restore the last session
working as expected.
{
"rmagatti/auto-session",
commit = "c8b2f4048f846387361bd04cc185bf1aa7d2e3d1",
lazy = false,
config = function()
require("auto-session").setup({
log_level = "debug",
auto_session_enabled = true,
auto_session_create_enabled = true,
auto_save_enabled = true,
auto_restore_enabled = true,
auto_session_enable_last_session = true,
auto_session_allowed_dirs = { "~/git/*" },
--cwd_change_handling = {
-- restore_upcoming_session = false,
--},
pre_save_cmds = {
function()
-- close all floating windows, then wipeout unlisted buffers to prevent error after auto restoring session
end
}
})
end,
}
System Information
- Session Options : blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal
- OS : EndeavourOS Linux x86_64 6.1.12-arch1-1
- LunarVim version : v0.9.0-dev-1014+g286777c33
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-10 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wno-unused-result -Wimplicit-fallthrough -Wvla -fno-common -fdiagnostics-color=always -fstack-protector-strong -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DMIN_LOG_LEVEL=3 -DNVIM_UNIBI_HAS_VAR_FROM -I/home/runner/work/neovim/neovim/.deps/usr/include/luajit-2.1 -I/usr/include -I/home/runner/work/neovim/neovim/.deps/usr/include -I/home/runner/work/neovim/neovim/.deps/usr/include -I/home/runner/work/neovim/neovim/.deps/usr/include -I/home/runner/work/neovim/neovim/.deps/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include -I/home/runner/work/neovim/neovim/build/cmake.config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/home/runner/work/neovim/neovim/.deps/usr/include -I/home/runner/work/neovim/neovim/.deps/usr/include
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/share/nvim"
Run :checkhealth for more info
My config
@boydaihungst, can you paste the debug logs here?
Of cause.
- First I removed all auto saved session file.
- Then open nvim with cmd: lvim
- Then I open nvim-tree to open random file in
/home/huyhoang/git/vue-enterprise-boilerplate
project root folder - It won't open at first time, I have to open it again.
- After that, open nvim-tree again, then move back to folder
/home/huyhoang/git/nuxt-app
- Open any file in
nuxt-app
, all buffer deleted, include the one from nuxt-app.
--- Autocommands ---
debug: ==== Pager mode
debug: sessions_dir, session_file
debug: ==== Using session DIR
debug: ==== Session Name:
debug: ==== is_readable
debug: ==== is_readable
debug: DirChangedPre
debug: cwd: /home/huyhoang/git/vue-enterprise-boilerplate
debug: target: /home/huyhoang
debug: changed window: true
debug: scope: global
continuing in nvim_exec() called at FileType Autocommands for "*":0
debug: DirChangedPre
debug: cwd: /home/huyhoang
debug: target: /home/huyhoang/git/vue-enterprise-boilerplate
debug: changed window: false
debug: scope: global
debug: ==== is_allowed_dirs_enabled
debug: bypass_save_by_filetype: false
debug: ==== SaveSession
debug: Session saved at /home/huyhoang/.local/share/nvim/sessions/\%home\%huyhoang.vim
3 buffers deleted
debug: DirChangedPre
debug: cwd: /home/huyhoang/git
debug: target: /home/huyhoang/git/vue-enterprise-boilerplate
debug: changed window: true
debug: scope: global
debug: DirChangedPre
debug: cwd: /home/huyhoang/git/vue-enterprise-boilerplate
debug: target: /home/huyhoang/git/nuxt-app
debug: changed window: false
debug: scope: global
debug: ==== is_allowed_dirs_enabled
debug: bypass_save_by_filetype: false
debug: ==== SaveSession
debug: Session saved at /home/huyhoang/.local/share/nvim/sessions/\%home\%huyhoang\%git\%vue-enterprise-boilerplate.vim
4 buffers deleted
debug: ==== SaveSession
info: Session saved at /home/huyhoang/.local/share/nvim/sessions/\%home\%huyhoang\%git\%nuxt-app.vim
debug: ==== is_allowed_dirs_enabled
debug: bypass_save_by_filetype: false
debug: ==== SaveSession
debug: Session saved at /home/huyhoang/.local/share/nvim/sessions/\%home\%huyhoang\%git\%nuxt-app.vim
Here are nvimtree config, in case you needs:
nvimtree.setup.view.adaptive_size = false
nvimtree.setup.view.side = "left"
nvimtree.setup.renderer.icons.show.git = false
nvimtree.setup.renderer.full_name = false
nvimtree.setup.view.number = true
nvimtree.setup.view.relativenumber = true
nvimtree.setup.renderer.indent_markers.enable = true
nvimtree.setup.hijack_netrw = false
nvimtree.setup.disable_netrw = false
nvimtree.setup.filters.custom = {}
The rest from lunarvim nvimtree.lua
Just met the issue. It's wired, because it occurs only in my Mac Mini, Windows and Linux with the same issue and same neovim version never meet the issue. The error is
Disabling auto save. Please check for errors in your config. Error:
vim/_editor.lua:421: nvim_exec2()../Users/winterreise/.local/share/nvim/sessions/%Users%winterreise%leetcode-rust_master.vim, line 51: Vim(unlet):E108: 无此变量:"SessionLoad"
And the session vim is:
let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
let GuiLoaded = 1
let NvimTreeSetup = 1
let ScopeState = "{\"last_tab\":1,\"cache\":[[\"\\/Users\\/winterreise\\/leetcode-rust\\/src\\/solution\\/s1441_build_an_array_with_stack_operations.rs\",\"\"]]}"
let GuiWindowFullScreen = 0
let GuiWindowMaximized = 0
let GuiWindowFrameless = 0
let GuiWindowId = 140523127280704
let GuiLinespace = 0
let GuiFont = "DejaVuSansM Nerd Font:h14"
let NvimTreeRequired = 1
silent only
silent tabonly
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
set shortmess=aoOA
else
set shortmess=aoO
endif
badd +116 ~/leetcode-rust/src/solution/s1441_build_an_array_with_stack_operations.rs
argglobal
%argdel
edit ~/leetcode-rust/src/solution/s1441_build_an_array_with_stack_operations.rs
argglobal
let s:l = 116 - ((115 * winheight(0) + 46) / 93)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 116
normal! 030|
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=1
let &shortmess = s:shortmess_save
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
set hlsearch
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
The No such variable: "SessionLoad"
error is usually caused when a session gets loaded while in the process of already loading a session. Consider a normal session file (with curdir
in sessionoptions
):
let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
cd ~/tmp/a
...
let &g:so = s:so_save | let &g:siso = s:siso_save
set hlsearch
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
The cd ~/tmp/a
call will change the directory, which, if cwd_change_handling = true
will trigger an event that could trigger loading the session again. That will let SessionLoad = 1
again but that's a nop, then it will cd ~/tmp/a
again but that's also a nop because we're already in that directory, and finally it will unlet SessionLoad
which clears it. Then the original load will start processing again and when it gets to unlet SessionLoad
it generates an error because SessionLoad
was already cleared by the session load triggered by the cd ~/tmp/a
I thought I'd fixed this bug in PR #315 but I now realize that my fix only covers some cases (auto restored sessions and :AutoSession search
and :Telescope session-lens
) but it doesn't cover :SessionRestore
. The real fix is to move the restore_in_progress flags into RestoreSession. I'll put together a PR.
@3rd what broke for you in https://github.com/rmagatti/auto-session/commit/7186e6148e8de6fb58403cf6596a92dfc1a94f09?
Hey, it breaks here: https://github.com/rmagatti/auto-session/blob/08c279882d4117a3e6ade1a014f7cf4af7c34fec/lua/auto-session/init.lua#L718-L721 table.concat outputs a string, json.decode(string[1]) errors
I think I got the wrong commit / the changes trigger that path, saw that part was changed a while ago. Thanks for the plugin, it's great ^_^
@3rd Can you share the specific error you're getting?
And is it possible for you to post your session_control.json
file (by default in vim.fn.stdpath "data" .. "/auto_session/")
?
Hey, of course!
Error:
Error detected while processing VimEnter Autocommands for "*":
Error executing lua callback: ...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:721: Expected value but found unexpected end of string at character 2
stack traceback:
[C]: in function 'decode'
...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:721: in function 'write_to_session_control_json'
...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:898: in function 'restore'
...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:940: in function 'AutoRestoreSession'
...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:811: in function 'auto_restore_session_at_vim_enter'
...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:1187: in function <...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:1161>
session_control.json
{"current":"\/home\/rabbit\/.cache\/nvim\/session\/%home%rabbit%brain%config.vim","alternate":"\/home\/rabbit\/.cache\/nvim\/session\/%home%rabbit%brain%core%ui%cli.vim"}
I'll have a PR for this later today. Looks like it was introduced in #322
@3rd If you're up for it, I'd love to have someone test out the fix for this issue. If so, change your config as follows:
-- 'rmagatti/auto-session', 'cameronr/auto-session',
restart nvim, then bring up Lazy and find auto-session and update it (it should show up at the top saying there's an origin mismatch). then restart nvim and let me know if it fixes it.
It does work great with your changes, thank you!