From 421cbd5d4491893e303b69c84cd49d9a6c615ce6 Mon Sep 17 00:00:00 2001 From: pablopunk Date: Mon, 6 Jul 2026 12:05:55 +0000 Subject: [PATCH] Guard buffer.current pcall failure before adding current buffer [ai] --- lua/unclutter/buffer.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lua/unclutter/buffer.lua b/lua/unclutter/buffer.lua index c7fe3fc..74d1815 100644 --- a/lua/unclutter/buffer.lua +++ b/lua/unclutter/buffer.lua @@ -109,18 +109,26 @@ end ---@param buf number ---@return boolean buffer.listed = function(buf) - return vim.bo[buf].buflisted + local ok, listed = pcall(function() + return vim.bo[buf].buflisted + end) + return ok and listed end --- Return all listed buffers + the current buffer (even if it's not listed) ---@return table buffer.all = function() - local buf_list = vim.api.nvim_list_bufs() + local ok, buf_list = pcall(vim.api.nvim_list_bufs) + if not ok then + return {} + end local listed_buffers = vim.tbl_filter(buffer.listed, buf_list) local current_buf = buffer.current() - -- add current buffer to list if it's not listed - if current_buf ~= nil and not vim.tbl_contains(listed_buffers, current_buf) then + -- add current buffer to list if it's not listed and it's a valid buffer + if current_buf ~= nil + and buffer.is_valid(current_buf) + and not vim.tbl_contains(listed_buffers, current_buf) then table.insert(listed_buffers, current_buf) end