diff --git a/runtime/lua/vim/_system.lua b/runtime/lua/vim/_system.lua index 947aa5c86f..72de1288b1 100644 --- a/runtime/lua/vim/_system.lua +++ b/runtime/lua/vim/_system.lua @@ -245,7 +245,13 @@ local function spawn(cmd, opts, on_exit, on_error) local handle, pid_or_err = uv.spawn(cmd, opts, on_exit) if not handle then on_error() - error(('%s: "%s"'):format(pid_or_err, cmd)) + if opts.cwd and not uv.fs_stat(opts.cwd) then + error(("%s (cwd): '%s'"):format(pid_or_err, opts.cwd)) + elseif vim.fn.executable(cmd) == 0 then + error(("%s (cmd): '%s'"):format(pid_or_err, cmd)) + else + error(pid_or_err) + end end return handle, pid_or_err --[[@as integer]] end diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua index 5abd901a9d..52206b7906 100644 --- a/test/functional/lua/system_spec.lua +++ b/test/functional/lua/system_spec.lua @@ -55,9 +55,14 @@ describe('vim.system', function() describe('(' .. name .. ')', function() it('failure modes', function() t.matches( - 'ENOENT%: no such file .*: "non%-existent%-cmd"', + "ENOENT%: no such file .* %(cmd%): 'non%-existent%-cmd'", t.pcall_err(system, { 'non-existent-cmd', 'arg1', 'arg2' }, { text = true }) ) + + t.matches( + "ENOENT%: no such file .* %(cwd%): 'non%-existent%-cwd'", + t.pcall_err(system, { 'echo', 'hello' }, { cwd = 'non-existent-cwd', text = true }) + ) end) it('can run simple commands', function()