famiu/bufdelete.nvim

random error: invalid window id

ViRu-ThE-ViRuS opened this issue · 2 comments

|| E5108: Error executing lua: ...te/pack/packer/opt/bufdelete.nvim/lua/bufdelete/init.lua:61: Invalid window id: 1016
|| stack traceback:
|| 	[C]: in function 'nvim_win_set_buf'
|| 	...te/pack/packer/opt/bufdelete.nvim/lua/bufdelete/init.lua:61: in function 'buf_kill'
|| 	...te/pack/packer/opt/bufdelete.nvim/lua/bufdelete/init.lua:78: in function 'bufdelete'

I see this message, every once in a while when normally having 2 splits open and closing one of them using bufdelete(0, true) from the plugin.

That window id doesnt exist, and this error is shown, but the buffer still closes like it should after the error. Please advise as to how to debug this further.

famiu commented

Can you reproduce this error with a minimal config?

There was an issue in the code that selected "next buffer" to switch to when closing the second to last buffer in the buffer list ...

The math making that decision was (current_buffer_index +1) % number_of_buffers which was meant to wrap back to index one when closing the last buffer or select the buffer after the one being closed otherwise. However the order of operations is wrong so it was trying to select buffer index 0 when closing the second to last buffer.

This appears to have been fixed in this commit 93e71aa, if you update the plugin buffer closing and next buffer selections should work correctly. I believe this issue can be closed @famiu