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.
This commit is contained in:
lu-papagni 2026-03-03 20:30:20 +01:00 committed by Christian Clason
parent eb1f8e80cb
commit 4f5b3d1a6b

View file

@ -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)