fix(health): check for errors when executing commands. Closes #1599

This commit is contained in:
Folke Lemaitre 2024-07-02 13:42:53 +02:00
parent a9d7ade203
commit d0921f5b9b
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 10 additions and 6 deletions

View File

@ -37,6 +37,9 @@ function M.have(cmd, opts)
for _, c in ipairs(cmd) do for _, c in ipairs(cmd) do
if vim.fn.executable(c) == 1 then if vim.fn.executable(c) == 1 then
local version = vim.fn.system(c .. " " .. opts.version) or "" local version = vim.fn.system(c .. " " .. opts.version) or ""
if vim.v.shell_error ~= 0 then
opts.error(("failed to get version of {%s}\n%s"):format(c, version))
else
version = vim.trim(vim.split(version, "\n")[1]) version = vim.trim(vim.split(version, "\n")[1])
version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "") version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "")
if opts.version_pattern and not version:find(opts.version_pattern, 1, true) then if opts.version_pattern and not version:find(opts.version_pattern, 1, true) then
@ -47,6 +50,7 @@ function M.have(cmd, opts)
end end
end end
end end
end
if found then if found then
opts.ok(found) opts.ok(found)
return true return true