aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorLuca Papagni <89859659+lu-papagni@users.noreply.github.com>2026-03-14 19:06:38 +0100
committerGitHub <noreply@github.com>2026-03-14 19:06:38 +0100
commit88a217f57061e5c98c9278bf93b0282e33b3d3bf (patch)
tree5b955b77def489fba20dafb2125dbc2d88de32cc /lua
parentbot(parsers): update c3, elixir, erlang, fsharp, gitcommit, hyprlang, kotlin,... (diff)
downloadnvim-treesitter-88a217f57061e5c98c9278bf93b0282e33b3d3bf.tar
nvim-treesitter-88a217f57061e5c98c9278bf93b0282e33b3d3bf.tar.gz
nvim-treesitter-88a217f57061e5c98c9278bf93b0282e33b3d3bf.tar.bz2
nvim-treesitter-88a217f57061e5c98c9278bf93b0282e33b3d3bf.tar.lz
nvim-treesitter-88a217f57061e5c98c9278bf93b0282e33b3d3bf.tar.xz
nvim-treesitter-88a217f57061e5c98c9278bf93b0282e33b3d3bf.tar.zst
nvim-treesitter-88a217f57061e5c98c9278bf93b0282e33b3d3bf.zip
Show errors on `vim.system` failure (#8552)
Problem: `vim.system` throws an error when `uv.spawn` fails, in particular when `cmd` or `cwd` does not exist. This kills the coroutine, which makes the corresponding async call hang. Solution: Wrap `vim.system` in a function that catches any error and returns it as `stderr` in a `SystemObj`. Co-authored-by: Christian Clason <c.clason@uni-graz.at>
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/install.lua26
1 files changed, 25 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index b94b31027..2c564b9ab 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -97,7 +97,31 @@ end
local function system(cmd, opts)
local cwd = opts and opts.cwd or uv.cwd()
log.trace('running job: (cwd=%s) %s', cwd, table.concat(cmd, ' '))
- local r = a.await(3, vim.system, cmd, opts) --[[@as vim.SystemCompleted]]
+
+ ---vim.system throws an error when uv.spawn fails, in particular if cmd or cwd
+ ---does not exist. This kills the coroutine, so the async'ed call simply hangs.
+ ---Instead, we pass a wrapper that catches errors and propagates them as a proper
+ ---`SystemObj`.
+ ---TODO(clason): remove when https://github.com/neovim/neovim/issues/38257 is resolved.
+ ---@param _cmd string[]
+ ---@param _opts vim.SystemOpts
+ ---@param on_exit fun(result: vim.SystemCompleted)
+ ---@return vim.SystemObj?
+ local function system_wrap(_cmd, _opts, on_exit)
+ local ok, ret = pcall(vim.system, _cmd, _opts, on_exit)
+ if not ok then
+ on_exit({
+ code = 125,
+ signal = 0,
+ stdout = '',
+ stderr = ret --[[@as string]],
+ })
+ return nil
+ end
+ return ret --[[@as vim.SystemObj]]
+ end
+
+ local r = a.await(3, system_wrap, cmd, opts) --[[@as vim.SystemCompleted]]
a.schedule()
if r.stdout and r.stdout ~= '' then
log.trace('stdout -> %s', r.stdout)