Skip to content

Error executing vim.schedule lua callback Invalid 'line': out of range when using auto commands #868

Description

@lyz-code

Describe the bug

Whenever I have an auto command window open and I do a change on a task (such as clocking in a headline) I get the next traceback:

[orgmode] Clock starts at [2025-01-21 Tue 20:04]
Error executing vim.schedule lua callback: ...ocal/share/nvim/lazy/orgmode/lua/orgmode/colors/init.lua:158: Invalid 'line': out of range
stack traceback:
	[C]: in function 'nvim_buf_set_extmark'
	...ocal/share/nvim/lazy/orgmode/lua/orgmode/colors/init.lua:158: in function 'add_hr'
	...ocal/share/nvim/lazy/orgmode/lua/orgmode/agenda/init.lua:60: in function 'render'
	...ocal/share/nvim/lazy/orgmode/lua/orgmode/agenda/init.lua:279: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

Steps to reproduce

  • Open a file with the next content:
* TODO Heading 1                                                                  :t:
* DONE Heading 2
  SCHEDULED: <2025-01-01>
  • Open the today report <leader>oat
  • Clockin the heading 1 <leader>oxi
  • See the error

In the recording it only throws the error when I clock in on the TODO task as the other did not change the agenda.

Image

Expected behavior

No error is thrown

Emacs functionality

No response

Minimal init.lua

I've tried reproducing the error with this minimal configuration without success :(.

local tmp_dir = vim.env.TMPDIR or vim.env.TMP or vim.env.TEMP or "/tmp"
local nvim_root = tmp_dir .. "/nvim_orgmode"
local lazy_root = nvim_root .. "/lazy"
local lazypath = lazy_root .. "/lazy.nvim"

for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = nvim_root .. "/" .. name
end

-- Install lazy.nvim if not already installed
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable", -- latest stable release
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"nvim-orgmode/orgmode",
		event = "VeryLazy",
		ft = { "org" },
		config = function()
			require("orgmode").setup({
				org_agenda_files = {
					"*.org",
				},
				org_agenda_custom_commands = {
					t = {
						description = "Today",
						types = {
							{
								type = "tags_todo",
								match = "+t",
								org_agenda_overriding_header = "Today",
							},
							{
								type = "agenda",
								org_agenda_overriding_header = "Today's agenda",
								org_agenda_span = "day", -- can be any value as org_agenda_span
								org_agenda_tag_filter_preset = "-t",
							},
						},
					},
				},
			})
		end,
	},
}, {
	root = lazy_root,
	lockfile = nvim_root .. "/lazy.json",
	install = {
		missing = false,
	},
})

require("lazy").sync({
	wait = true,
	show = false,
})

However the previous recording is done with a similar orgmode configuration (using lazyvim):

return {
  {
    "nvim-orgmode/orgmode",
    event = "VeryLazy",
    config = function()
      require("orgmode").setup({
        org_agenda_files = {
          "*.org",
        },
        org_agenda_custom_commands = {
          t = {
            description = "Today",
            types = {
              {
                type = "tags_todo", -- Type can be agenda | tags | tags_todo
                match = "+t/-INACTIVE", --Same as providing a "Match:" for tags view <leader>oa + m, See: https://orgmode.org/manual/Matching-tags-and-properties.html
                org_agenda_overriding_header = "Today",
              },
              {
                type = "agenda",
                org_agenda_overriding_header = "Today's agenda",
                org_agenda_span = "day", -- can be any value as org_agenda_span
                org_agenda_tag_filter_preset = "-t",
              },
            },
          },
        },
      })
    end,
  },
}

It's probably due to a conflict with my other plugins but I haven't been able to find the culprit. Can you help me?

Screenshots and recordings

No response

OS / Distro

linux

Neovim version/commit

0.10.0

Additional context

No response

Activity

  1. changed the title [-]Error executing vim.schedule lua callback Invalid 'line': out of range[/-] [+]Error executing vim.schedule lua callback Invalid 'line': out of range when using auto commands[/+] on Jan 21, 2025
  2. kristijanhusak commented on Jan 21, 2025

    @kristijanhusak
    Member

    I'm fairly sure this happens because of noice. Can you try disabling it in your config and see if it happens?

  3. lyz-code commented on Jan 21, 2025

    @lyz-code
    Author

    It doesn't look to be the culprit, I've disabled almost everything. This is what lazy shows:

      Loaded (5)
        ● lazy.nvim 34.4ms  init.lua
        ● LazyVim 8.09ms  start
        ● nvim-treesitter 13.92ms  start
        ● nvim-treesitter-textobjects 2.88ms  VeryLazy
        ● orgmode 3.05ms  VeryLazy
    
  4. kristijanhusak commented on Jan 21, 2025

    @kristijanhusak
    Member

    Seems like your agenda is automatically reloading when you clock in/out. Do you have some custom code to achieve that?

  5. lyz-code commented on Jan 21, 2025

    @lyz-code
    Author

    Yep, that was it I have an autocomand for that

    vim.api.nvim_create_autocmd("BufWritePost", {
      pattern = "*.org",
      callback = function()
        local bufnr = vim.fn.bufnr("orgagenda") or -1
        if bufnr > -1 then
          require("orgmode").agenda:redo()
        end
      end,
    })

    You helped me create it in the past. I've thought of adding a sleep but it doesn't work either:

    vim.api.nvim_create_autocmd("BufWritePost", {
      pattern = "*.org",
      callback = function()
        local bufnr = vim.fn.bufnr("orgagenda") or -1
        if bufnr > -1 then
          -- require("orgmode").agenda:redo()
          -- Delay for 500ms (half second) before reloading
          vim.defer_fn(function()
            require("orgmode").agenda:redo()
          end, 500)
        end
      end,
    })

    Do you have an idea on how to fix it?

  6. kristijanhusak commented on Jan 21, 2025

    @kristijanhusak
    Member

    Should be fixed now.

  7. lyz-code commented on Jan 21, 2025

    @lyz-code
    Author

    Indeed it is, thanks as always ❤

  8. added a commit that references this issue on Jan 22, 2025
    e0ba9dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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