plenary.nvim icon indicating copy to clipboard operation
plenary.nvim copied to clipboard

[BUG] Job: `cannot resume dead coroutine` with `maximum-results`

Open cseickel opened this issue 3 years ago • 0 comments

I found a bug with the Job class: if you set maximum_results and the process encounters an error during execution, you will get this error message:

Error executing luv callback:
cannot resume dead coroutine
stack traceback:
        [builtin#36]: at 0x57ac5f2f4ad0
        [C]: in function 'wait'
        .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:218: in function 'shutdown'
        .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:343: in function <.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:342>

You can recreate it reliably with this example:

local Job = require("plenary.job")

Job:new({
  command = "find",
  args = {"/", "-iname", "e"},
  maximum_results = 10,
  on_start = function ()
    print("start")
  end,
  on_stdout = function(_, data, _)
    print(data)
  end,
  on_stderr = function(_, data, _)
    print(data)
  end,
  on_exit = function(_, code, _)
    print("exit", code)
  end,
}):start()

I am trying to fix it but it's proving more difficult than I anticipated. As far as I can see, the error is caused by vim.wait returning after everything has already been cleaned up. It will work fine for a normally executing process with a clean exit, but not in this situation where a process has errors. At least this applies to using the find command when it searches directories that you don't have permissions to.

cseickel avatar Mar 03 '22 13:03 cseickel