From e52eab070519f230e6d8bff071b5e619c379b7e4 Mon Sep 17 00:00:00 2001 From: Stefan Bartl Date: Tue, 4 Nov 2025 17:42:34 +0100 Subject: [PATCH] fix(tabufline): prevent invalid buffer ID error on BufAdd event Add buffer validation before accessing bufs[1] to prevent crash when using preview features in Neo-tree, FZF-lua, or Telescope. Checks table length and buffer validity before calling nvim_buf_get_name(). --- lua/nvchad/tabufline/lazyload.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/nvchad/tabufline/lazyload.lua b/lua/nvchad/tabufline/lazyload.lua index f89c6a61..8f3314ab 100644 --- a/lua/nvchad/tabufline/lazyload.lua +++ b/lua/nvchad/tabufline/lazyload.lua @@ -33,8 +33,10 @@ autocmd({ "BufAdd", "BufEnter", "tabnew" }, { -- remove unnamed buffer which isnt current buf & modified if args.event == "BufAdd" then - if #api.nvim_buf_get_name(bufs[1]) == 0 and not get_opt("modified", { buf = bufs[1] }) then - table.remove(bufs, 1) + if #bufs > 0 and api.nvim_buf_is_valid(bufs[1]) then + if #api.nvim_buf_get_name(bufs[1]) == 0 and not get_opt("modified", { buf = bufs[1] }) then + table.remove(bufs, 1) + end end end