Skip to content

Job sending output to buffer raises "E916: not a valid job" #1242

@lifepillar

Description

@lifepillar

I get the error in the subject with Vim 8.0.0071 under macOS. To reproduce, create the following vimrc_minimal:

set nocompatible

fun! SendToBuffer(cmd)
  let l:job = job_start(a:cmd, {
        \ "close_cb": "CloseCallback",
        \ "exit_cb": "ExitCallback",
        \ "out_io": "buffer"})
  execute  "bo split +buffer".ch_getbufnr(l:job, "out")
  wincmd p
endf

fun! CloseCallback(channel)
  call job_status(ch_getjob(a:channel))
endf

fun! ExitCallback(job, status)
  exe "echomsg" (a:status == 0 ? "'Success!'" : "'Failed.'")
endf

Then, run vim -u vimrc_minimal and execute:

:call SendToBuffer('ls')

Sometimes, the error is not raised: in that case, try the command repeatedly. This is what I eventually see in messages:

Success!
Error detected while processing function CloseCallback:
line    1:
E916: not a valid job

The specific command shouldn't matter (in fact, I first saw the error using git push), although some commands seem to cause the error more frequently than others.

[Edit: fixed typo in Vim version]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions