mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
fix(vim.system): improve error message when cwd does not exist
Problem:
vim.uv.spawn will emit ENOENT for either when the cmd or cwd do not
exist and does not tell you which.
Solution:
If an error occurs, check if cwd was supplied and included in the error
message if it does not exist.
(cherry picked from commit 532610388b
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
4cb2b19197
commit
3a0d37681f
@@ -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
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user