Skip to content

Commit

Permalink
fix(health): check for errors when executing commands. Closes #1599
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 2, 2024
1 parent a9d7ade commit d0921f5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lua/lazy/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ function M.have(cmd, opts)
for _, c in ipairs(cmd) do
if vim.fn.executable(c) == 1 then
local version = vim.fn.system(c .. " " .. opts.version) or ""
version = vim.trim(vim.split(version, "\n")[1])
version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "")
if opts.version_pattern and not version:find(opts.version_pattern, 1, true) then
opts.warn(("`%s` version `%s` needed, but found `%s`"):format(c, opts.version_pattern, version))
if vim.v.shell_error ~= 0 then
opts.error(("failed to get version of {%s}\n%s"):format(c, version))
else
found = ("{%s} `%s`"):format(c, version)
break
version = vim.trim(vim.split(version, "\n")[1])
version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "")
if opts.version_pattern and not version:find(opts.version_pattern, 1, true) then
opts.warn(("`%s` version `%s` needed, but found `%s`"):format(c, opts.version_pattern, version))
else
found = ("{%s} `%s`"):format(c, version)
break
end
end
end
end
Expand Down

0 comments on commit d0921f5

Please sign in to comment.