Skip to content

fix: add nil check to git status #2533

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

Merged
merged 3 commits into from
Nov 19, 2023
Merged

Conversation

hlmtre
Copy link
Contributor

@hlmtre hlmtre commented Nov 14, 2023

Requisite config:

local nvim_tree_setup = function()
  require('nvim-tree').setup({
    on_attach = on_attach,
    diagnostics = {
      enable = true,
    },
    update_focused_file = {
      enable = true,
      update_root = false,
    },
    respect_buf_cwd = false,
    sync_root_with_cwd = false,
    view = {
      width = 40,
      side = 'right',
      --mappings = {
      --  custom_only = false,
      --  list = {
      --    { key = { '<CR>', '<Tab>' }, action = 'edit' },
      --  },
      --},
    },
  })
end

Occasionally, with the above config, nvim-tree will spit out the following error message:

node.lua attempt to index local 'status' a nil value

creating a nice big traceback of the complaint and stealing focus briefly. You can immediately press q and leave it and go back to what you were doing, but it happens a few times in a couple seconds, then chills out.

Working theory: I think there were points at which the git status of a node wasn't set, and nvim-tree would still try to get its git status, leading to ... local 'status' a nil value. This change simply quietly does not return anything at the time of that check (but we don't care, it'll get run again soon).

Error executing vim.schedule lua callback: .../nvim/lazy/nvim-tree.lua/lua/nvim-tree/explorer/node.lua:19: attempt to index local 'status' (a nil value)
stack traceback:
        .../nvim/lazy/nvim-tree.lua/lua/nvim-tree/explorer/node.lua:19: in function 'get_status'
        .../nvim/lazy/nvim-tree.lua/lua/nvim-tree/explorer/node.lua:46: in function 'update_git_status'
        ...vim/lazy/nvim-tree.lua/lua/nvim-tree/explorer/reload.lua:54: in function 'update_parent_statuses'
        ...vim/lazy/nvim-tree.lua/lua/nvim-tree/explorer/reload.lua:180: in function 'callback'
        ...vim/lazy/nvim-tree.lua/lua/nvim-tree/explorer/reload.lua:28: in function 'callback'
        ...share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/git/init.lua:111: in function 'callback'
        ...are/nvim/lazy/nvim-tree.lua/lua/nvim-tree/git/runner.lua:194: in function 'callback'
        ...are/nvim/lazy/nvim-tree.lua/lua/nvim-tree/git/runner.lua:101: in function 'on_finish'
        ...are/nvim/lazy/nvim-tree.lua/lua/nvim-tree/git/runner.lua:113: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

@Akmadan23 Akmadan23 changed the title fix for nil status error messages fix: for nil status error messages Nov 14, 2023
@Akmadan23 Akmadan23 changed the title fix: for nil status error messages fix: add nil check to git status Nov 14, 2023
@Akmadan23
Copy link
Collaborator

Thank you for finding this one! Missing nil checks can be really annoying sometimes

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

nil resulting from this function i.e. node.git_status is checked / handled in all obvious places so we are OK.

@alex-courtis alex-courtis merged commit 633811c into nvim-tree:master Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants