Skip to content

[Bug] side_by_side.lua:466: Invalid 'buffer': Expected Lua number #298

@jemag

Description

@jemag

Currently when using this plugin along with mosheavni/yaml-companion.nvim, there is an issue with the check

    if not vim.api.nvim_buf_is_valid(original_info.bufnr) or not vim.api.nvim_buf_is_valid(modified_info.bufnr) then
      return
    end

Since the value passed to nvim_buf_is_valid can be nil.

Here is the full error output:

Error executing vim.schedule lua callback: BufReadPost Autocommands for "*": Vim(append):Error executing lua callback: ...-neovim-unwrapped-0.11.6/share/nvim/runtime/filetype.lua:36: BufReadPost Autocommands for "*"..FileType Autocommands for "*"..LspAttach Autocommands for "*": Vim(append):Error executing vim.schedule lua callback: ...lazy/codediff.nvim/lua/codediff/ui/view/side_by_side.lua:466: Invalid 'buffer': Expected Lua number
stack traceback:
    [C]: in function 'nvim_buf_is_valid'
    ...lazy/codediff.nvim/lua/codediff/ui/view/side_by_side.lua:466: in function <...lazy/codediff.nvim/lua/codediff/ui/view/side_by_side.lua:459>
    [C]: in function 'wait'
    ...wrapped-0.11.6/share/nvim/runtime/lua/vim/lsp/client.lua:749: in function 'request_sync'
    ...lazy/yaml-companion.nvim/lua/yaml-companion/lsp/util.lua:24: in function 'get_jsonschema'
    ...m/lazy/yaml-companion.nvim/lua/yaml-companion/schema.lua:98: in function 'current'
    .../yaml-companion.nvim/lua/yaml-companion/context/init.lua:74: in function 'autodiscover'
    .../yaml-companion.nvim/lua/yaml-companion/context/init.lua:184: in function 'setup'
    ...vim/lazy/yaml-companion.nvim/lua/yaml-companion/init.lua:50: in function <...vim/lazy/yaml-companion.nvim/lua/yaml-companion/init.lua:38>
    [C]: in function 'nvim_exec_autocmds'
    ...wrapped-0.11.6/share/nvim/runtime/lua/vim/lsp/client.lua:1037: in function 'on_attach'
    ...
    ...ovim-unwrapped-0.11.6/share/nvim/runtime/lua/vim/lsp.lua:628: in function <...ovim-unwrapped-0.11.6/share/nvim/runtime/lua/vim/lsp.lua:627>
    [C]: in function 'nvim_cmd'
    ...-neovim-unwrapped-0.11.6/share/nvim/runtime/filetype.lua:36: in function <...-neovim-unwrapped-0.11.6/share/nvim/runtime/filetype.lua:35>
    [C]: in function 'pcall'
    vim/shared.lua: in function <vim/shared.lua:0>
    [C]: in function '_with'
    ...-neovim-unwrapped-0.11.6/share/nvim/runtime/filetype.lua:35: in function <...-neovim-unwrapped-0.11.6/share/nvim/runtime/filetype.lua:10>
    [C]: in function 'bufload'
    ...lazy/codediff.nvim/lua/codediff/ui/view/side_by_side.lua:629: in function 'update'
    ...m/lazy/codediff.nvim/lua/codediff/ui/explorer/render.lua:387: in function <...m/lazy/codediff.nvim/lua/codediff/ui/explorer/render.lua:377>
stack traceback:
    [C]: in function '_with'
    ...-neovim-unwrapped-0.11.6/share/nvim/runtime/filetype.lua:35: in function <...-neovim-unwrapped-0.11.6/share/nvim/runtime/filetype.lua:10>
    [C]: in function 'bufload'
    ...lazy/codediff.nvim/lua/codediff/ui/view/side_by_side.lua:629: in function 'update'
    ...m/lazy/codediff.nvim/lua/codediff/ui/explorer/render.lua:387: in function <...m/lazy/codediff.nvim/lua/codediff/ui/explorer/render.lua:377>
stack traceback:
    [C]: in function 'bufload'
    ...lazy/codediff.nvim/lua/codediff/ui/view/side_by_side.lua:629: in function 'update'
    ...m/lazy/codediff.nvim/lua/codediff/ui/explorer/render.lua:387: in function <...m/lazy/codediff.nvim/lua/codediff/ui/explorer/render.lua:377>

I haven't had the time to investigate much, but my very surface understanding is that something like the following might be happening:

Expected execution order:          Actual execution order:
─────────────────────────         ─────────────────────────
1. prepare_buffer (bufnr=nil)     1. prepare_buffer (bufnr=nil)
2. define render_everything       2. define render_everything  
3. bufload()                      3. bufload() starts...
4. bufnr = 42                        ├─ autocmds fire
5. render_everything() runs          ├─ yaml-companion runs
   (bufnr is now 42 ✓)               ├─ vim.wait() called
                                     ├─ render_everything() runs
                                     │  (bufnr is still nil ✗) ← CRASH
                                     └─ bufload() never returns
                                  4. bufnr = 42 (never reached)

Let me know if you need additional information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions