summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/_system.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2025-04-29 10:48:18 +0100
committerLewis Russell <me@lewisr.dev>2025-05-29 13:59:33 +0100
commit532610388bb09fef6d0de8929092d4dc32f781bf (patch)
tree26f0186a932a009a7846e9af9edb1995b1649b8c /runtime/lua/vim/_system.lua
parentcc264d51aba802d7f536cc3680b3af2d13ed1889 (diff)
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.
Diffstat (limited to 'runtime/lua/vim/_system.lua')
-rw-r--r--runtime/lua/vim/_system.lua8
1 files changed, 7 insertions, 1 deletions
diff --git a/runtime/lua/vim/_system.lua b/runtime/lua/vim/_system.lua
index c5cb9b73ea..e40229de63 100644
--- a/runtime/lua/vim/_system.lua
+++ b/runtime/lua/vim/_system.lua
@@ -246,7 +246,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