nvim-lualine/lualine.nvim

Bug: Invalid window ID

refLog2112 opened this issue · 9 comments

Self Checks

  • I'm using the latest lualine.
  • I didn't find the issue in existing issues or PRs.

How to reproduce the problem

  1. Set buffers in Split View
  2. Open command line

Expected behaviour

No error message is shown

Actual behaviour

Error detected while processing ModeChanged Autocommands for "*":
E5108: Error executing lua .../.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:429: Invalid window id: 1001
stack traceback:
	[C]: in function 'nvim_win_call'
	.../.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:429: in function 
        <.../.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:318>

Minimal config to reproduce the issue

  1. Noice plugin
  2. globalstatus = true

Additional information

Everything works fine if a single buffer is in focus

liath commented

Added some guards around the failing line and it seems to clear this up:

diff --git a/lua/lualine.lua b/lua/lualine.lua
index 6093049..e75f79e 100644
--- a/lua/lualine.lua
+++ b/lua/lualine.lua
@@ -426,8 +426,13 @@ local function refresh(opts)
           and vim.fn.win_gettype(refresh_real_curwin) == 'popup'
           and refresh_real_curwin
         or win
-      local stl_cur = vim.api.nvim_win_call(refresh_real_curwin, M.statusline)
+
+      local win_is_num = type(refresh_real_curwin) == "number"
+      local win_is_valid = win_is_num and vim.api.nvim_win_is_valid(refresh_real_curwin)
+
+      local stl_cur = win_is_valid and vim.api.nvim_win_call(refresh_real_curwin, M.statusline) or ""
       local stl_last = modules.nvim_opts.get_cache('statusline', { window = set_win })
+
       if stl_cur or stl_last then
         modules.nvim_opts.set('statusline', stl_cur, { window = set_win })
       end

There's probably a better fix that would answer why refresh_real_curwin is ocassionally:

  • nil
  • an invalid window id (perhaps a race happening somewhere?)

@liath Indeed this fix kind of works, but is hiding the status line.
@folke is there something that can be related to Noice?

Regardless of how many splits are there, the Invalid window id: 1001 is always the error cause.

liath commented

I reverted my change to see if I could find a better solution but can't seem to reproduce now. I pulled updates fwiw, maybe it'll help you @refLog2112

folke commented

I dont see this issse. What are the exact steps to reproduce this using Noice and lualine?

@folke Here are the steps with a little demo

  1. Open 2+ buffers and put them in split
  2. Switch between the splits
  3. Open command line in each
    steps
folke commented

Still can't reproduce. Since both noice and lualine are part of LazyVim which is used by thousands of people, I would also be very surprised there's an interop issue there.

Feel free to open an issue in the noice repo with a minimal repro as instructed in the issue template.

The issue seems to be a job started with plenary. Closing this issue.

@refLog2112 Running into the same issue. Would you mind sharing what your fix was?