Skip to content

Commit

Permalink
fix: UNKNOWN PLUGIN error resulting from unloaded buffers (akinsho#928)
Browse files Browse the repository at this point in the history
Problem:
Currently when checking if a buffer is valid, we use the function nvim_buf_is_valid, however there is an edge case here described in the documentation where a buffer could have been unloaded, but still be "valid". If a buffer is unloaded and valid then referencing buflisted will result in a (UNKNOWN PLUGIN): Error executing lua: attempt to call a number value error.

Solution:
Instead of nvim_buf_is_valid we use nvim_buf_is_loaded which checks both whether a buffer is valid and loaded. This way we never attempt to reference buflisted of unloaded or invalid buffers.

This PR should at least partially address akinsho#869. Applying the patch removes these errors for my config when invoking Neovim via nvim .. Because this error is so generic, it's possible that there could be more than one cause.
  • Loading branch information
prettymuchbryce authored Jun 23, 2024
1 parent 99337f6 commit 6ac7e4f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lua/bufferline/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ M.path_sep = fn.has("win32") == 1 and "\\" or "/"
--- @param buf_num integer
function M.is_valid(buf_num)
if not buf_num or buf_num < 1 then return false end
local exists = vim.api.nvim_buf_is_valid(buf_num)
return vim.bo[buf_num].buflisted and exists
local exists = vim.api.nvim_buf_is_loaded(buf_num)
if not exists then return false end
return vim.bo[buf_num].buflisted
end

---@return integer
Expand Down

0 comments on commit 6ac7e4f

Please sign in to comment.