From 4f5b3d1a6b195da2ca5ffd14184ca585cf8c4457 Mon Sep 17 00:00:00 2001 From: lu-papagni Date: Tue, 3 Mar 2026 20:30:20 +0100 Subject: [PATCH] fix(install): show error on `vim.system` failure Problem: Operations fail silently when a system command cannot be executed. Solution: Implement a helper function for `system` that resumes execution on error, retrieving the error message. --- lua/nvim-treesitter/install.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index b94b31027..333f17526 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -97,7 +97,26 @@ 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]] + + ---@param _cmd string[] + ---@param _opts vim.SystemOpts + ---@param on_exit fun(result: vim.SystemCompleted) + ---@return vim.SystemObj? + local function safe_system(_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, safe_system, cmd, opts) --[[@as vim.SystemCompleted]] a.schedule() if r.stdout and r.stdout ~= '' then log.trace('stdout -> %s', r.stdout)