Skip to content

Arithmetic on a nil value error when opening file in child git repo with NvimTree Open #2906

Closed
@ianhomer

Description

@ianhomer

Description

With NvimTree open, when I open a file (with Telescope oldfiles) in a child project directory of the root directory and this child project directory is a git repository then I get the following error.

Error executing vim.schedule lua callback: ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:69: attempt to perform
 arithmetic on a nil value
stack traceback:
        ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:69: in function 'populate_children'
        ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:92: in function 'explore'
        ...cker/start/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:267: in function '_load'
        ...cker/start/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:73: in function 'expand'
        ...vim-tree.lua/lua/nvim-tree/actions/finders/find-file.lua:66: in function '_apply_fn_on_node'
        .../nvim-tree.lua/lua/nvim-tree/iterators/node-iterator.lua:63: in function 'iter'
        .../nvim-tree.lua/lua/nvim-tree/iterators/node-iterator.lua:66: in function 'iterate'
        ...vim-tree.lua/lua/nvim-tree/actions/finders/find-file.lua:76: in function 'fn'
        ...t/nvim-tree.lua/lua/nvim-tree/actions/tree/find-file.lua:64: in function 'fn'
        ...n/site/pack/packer/start/nvim-tree.lua/lua/nvim-tree.lua:280: in function 'callback'
        .../pack/packer/start/nvim-tree.lua/lua/nvim-tree/utils.lua:455: in function <.../pack/packer/start/nvim-tree.lua/lua
/nvim-tree/utils.lua:454>

The only way I know that can trigger this error is when I open a file with :Telescope oldfiles, it doesn't error if I open with other ways, e.g. open with :e or :Telescope find_files. A little bizarre and I'm not sure why that particular usage triggers this issue. Note also I've only reproduced this issue when the child directory is a git repository. This usage happens to be a very common usage for me. I open nvim in parent directory that has many git repositories, I open NvimTree first (out of habit, and actually if I open nvim-tree after I open the file I don't get the error) and then open a recently opened file. I only started seeing this error only started happening recently, perhaps in the last week or so.

I reduced the nvim tree config to a configuration where this error still happens.

    update_focused_file = {
      enable = true,
    },
    renderer = {
      highlight_opened_files = "all",
    },

If I remove either of those configuration the error does not happen anymore.

This error occurs after the fix for bugs with similar error signal was merged, i.e. after #2874 which fixed #2868 and #2866

Candidate fix created at #2907

Neovim version

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1725453128
Run "nvim -V1 -v" for more info

Operating system and version

MacOS

Windows variant

No response

nvim-tree version

d41b4ca

Clean room replication

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  })
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing nvim-tree and dependencies.")
  vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup({
    update_focused_file = {
      enable = true,
    },
    renderer = {
      highlight_opened_files = "all",
    },
  })
  require("telescope").setup({})
end

Steps to reproduce

  1. git clone [email protected]:nvim-tree/nvim-tree.lua.git
  2. nvim -nu nvim-tree-min.lua
  3. :e nvim-tree.lua/scripts/doc-comments.sh
  4. close nvim
  5. nvim -nu nvim-tree-min.Lua
  6. :NvimTreeOpen
  7. :Telescope oldfiles
  8. select doc-comments.sh from history

Expected behavior

No error thrown

Actual behavior

I get the error

Error executing vim.schedule lua callback: ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:69: attempt to perform
 arithmetic on a nil value
stack traceback:
        ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:69: in function 'populate_children'
        ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:92: in function 'explore'
        ...cker/start/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:267: in function '_load'
        ...cker/start/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:73: in function 'expand'
        ...vim-tree.lua/lua/nvim-tree/actions/finders/find-file.lua:66: in function '_apply_fn_on_node'
        .../nvim-tree.lua/lua/nvim-tree/iterators/node-iterator.lua:63: in function 'iter'
        .../nvim-tree.lua/lua/nvim-tree/iterators/node-iterator.lua:66: in function 'iterate'
        ...vim-tree.lua/lua/nvim-tree/actions/finders/find-file.lua:76: in function 'fn'
        ...t/nvim-tree.lua/lua/nvim-tree/actions/tree/find-file.lua:64: in function 'fn'
        ...n/site/pack/packer/start/nvim-tree.lua/lua/nvim-tree.lua:280: in function 'callback'
        .../pack/packer/start/nvim-tree.lua/lua/nvim-tree/utils.lua:455: in function <.../pack/packer/start/nvim-tree.lua/lua
/nvim-tree/utils.lua:454>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions