-
-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix potential nil access #821
Conversation
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' ```
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused why this check wouldn't be enough already? if element is falsy then it should use the last item in the list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is only 1 buffer, it appears that there isn't any items in the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I insert:
vim.notify(vim.inspect(element))
vim.notify(vim.inspect(list))
in between lines 120 and 121, the output is nil
and {}
respectively.
Co-authored-by: Akin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏾
* 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]>
If one uses this method mapped to keys and accidentally hit a number with a non-existing buffer,
element
can be nil: