Skip to content

Commit

Permalink
fix(commands): potential nil access (#821)
Browse files Browse the repository at this point in the history
* Fix potential nil access

If one uses this method mapped to keys and accidentally hit a number with a non-existing buffer, `element` can be nil:

```
E5108: Error executing lua: ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:122: attempt to index local 'element' (a nil value)
stack traceback:
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:122: in function 'go_to'
```

* Update lua/bufferline/commands.lua

Co-authored-by: Akin <[email protected]>

---------

Co-authored-by: Akin <[email protected]>
  • Loading branch information
dsully and akinsho authored Oct 2, 2023
1 parent 6ecd37e commit 6e96fa2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lua/bufferline/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ function M.go_to(num, absolute)
local list = absolute and state.components or state.visible_components
local element = list[num]
if num == -1 or not element then element = list[#list] end
open_element(element.id)

if element then
open_element(element.id)
end
end

---@param current_state bufferline.State
Expand Down

0 comments on commit 6e96fa2

Please sign in to comment.