Skip to content

bug: E5108 "Invalid buffer" whe toggle the render #260

@sadtab

Description

@sadtab

Neovim version (nvim -v)

0.10.2

Neovim distribution

My own

Operating system

Ubuntu

Terminal emulator / GUI

Alacritty

Describe the bug

When several markdown files are opened and some of them are modified with or without writing , toggling the renderer can cause this error log :

   Error  04:11:20 PM msg_show.emsg E5108: Error executing lua: ...y/render-markdown.nvim/lua/render-markdown/core/util.lua:131: Invalid buffer id: 4
stack traceback:
	[C]: in function 'nvim_buf_get_name'
	...y/render-markdown.nvim/lua/render-markdown/core/util.lua:131: in function 'file_name'
	...zy/render-markdown.nvim/lua/render-markdown/core/log.lua:61: in function 'buf'
	...azy/render-markdown.nvim/lua/render-markdown/core/ui.lua:79: in function 'update'
	...azy/render-markdown.nvim/lua/render-markdown/manager.lua:47: in function 'set_all'
	...im/lazy/render-markdown.nvim/lua/render-markdown/api.lua:17: in function 'toggle'
	/home/sadegh/.config/nvim/lua/helpers.lua:47: in function </home/sadegh/.config/nvim/lua/helpers.lua:44>

I looked a little in the source code and it seems the autocmd at

vim.api.nvim_create_autocmd('FileType', {

is registered in all files and if somehow there is a temporary buffer that comes into existence and is wiped out right after (maybe another plugin is doing it) is queued in the plugin internals

I changed autocmd to

    vim.api.nvim_create_autocmd('FileType', {
        pattern = { 'markdown' },
        group = M.group,
        callback = function(args)
            M.attach(args.buf)
        end,
    })

And it seems to be working, I see this autocmd is intentionally registered for all the files but maybe there is a better way of doing it

Expected behavior

no invalid buffer error

Healthcheck output

render-markdown: require("render-markdown.health").check()

render-markdown.nvim [version] ~
- OK plugin 7.7.3
- OK neovim >= 0.10

render-markdown.nvim [configuration] ~
- OK valid

render-markdown.nvim [nvim-treesitter] ~
- OK installed
- OK markdown: parser installed
- OK markdown: highlight enabled
- OK markdown_inline: parser installed
- OK markdown_inline: highlight enabled

render-markdown.nvim [executables] ~
- OK none to check

render-markdown.nvim [conflicts] ~
- OK headlines: not installed
- OK obsidian: not installed

Plugin configuration

{
    "MeanderingProgrammer/render-markdown.nvim",
    dependencies = { "nvim-treesitter/nvim-treesitter", "echasnovski/mini.nvim" },
    opts = {
      file_types = { "markdown", "noice" },
      -- enabled = false, -- Disable by default
      code = {
        sign = false,
        width = "block",
        -- right_pad = 1,
        style = "full",
        language_pad = 0,
        language_name = true,
        position = "right",
      },
      dash = {
        -- Turn on / off thematic break rendering
        enabled = true,
        icon = "󰮸 ",
        width = 40, -- textwidth/2 because of 2 characters as icon
        highlight = "RenderMarkdownDash",
      },
      heading = {
        enabled = true,
        width = "block",
        sign = false,
        icons = {
          -- "󰎤  ",
          -- " 󰎩  ",
          -- "  󰎪  ",
          -- "   󰎮  ",
          -- "    󰎱  ",
          -- "      󰎵  ",
          "",
          "",
          "",
          "",
          "",
          "",
        },
        -- left_margin = 2,
      },
      bullet = {
        -- Turn on / off list bullet rendering
        enabled = true,
        right_pad = 1,
      },
      latex = {
        enabled = false,
        -- Executable used to convert latex formula to rendered unicode
        converter = "latex2text",
        -- Highlight for LaTeX blocks
        highlight = "RenderMarkdownMath",
        -- Amount of empty lines above LaTeX blocks
        top_pad = 0,
        -- Amount of empty lines below LaTeX blocks
        bottom_pad = 0,
      },
      win_options = {
        conceallevel = {
          default = 0,
          rendered = 3,
        },
      },
      render_modes = { "n", "c", "t", "i" },
    },
    ft = { "markdown", "norg", "rmd", "org", "noice" },
  },

Plugin error log

 Error 04:11:20 PM msg_show.emsg E5108: Error executing lua: ...y/render-markdown.nvim/lua/render-markdown/core/util.lua:131: Invalid buffer id: 4
stack traceback:
[C]: in function 'nvim_buf_get_name'
...y/render-markdown.nvim/lua/render-markdown/core/util.lua:131: in function 'file_name'
...zy/render-markdown.nvim/lua/render-markdown/core/log.lua:61: in function 'buf'
...azy/render-markdown.nvim/lua/render-markdown/core/ui.lua:79: in function 'update'
...azy/render-markdown.nvim/lua/render-markdown/manager.lua:47: in function 'set_all'
...im/lazy/render-markdown.nvim/lua/render-markdown/api.lua:17: in function 'toggle'
/home/sadegh/.config/nvim/lua/helpers.lua:47: in function </home/sadegh/.config/nvim/lua/helpers.lua:44>

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided the text contained in all screenshots as raw text in this issue. This means if there is a screenshot below it is the copy pasted contents of the file in the screenshot. I understand that my issue will be closed if I have not.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions