From a75d950b8f356733ad2d20c4bdb794179e6d4ff1 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 29 Jun 2024 13:52:50 +0200 Subject: [PATCH] fix(process): deal with process errors --- lua/lazy/manage/process.lua | 9 +++------ lua/lazy/util.lua | 13 +++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lua/lazy/manage/process.lua b/lua/lazy/manage/process.lua index f29d978..c4a4baf 100644 --- a/lua/lazy/manage/process.lua +++ b/lua/lazy/manage/process.lua @@ -42,8 +42,8 @@ function Process.new(cmd, opts) opts = opts or {} opts.args = opts.args or {} if type(cmd) == "table" then - self.cmd = table.remove(cmd, 1) - vim.list_extend(opts.args, cmd) + self.cmd = cmd[1] + vim.list_extend(opts.args, vim.list_slice(cmd, 2)) else self.cmd = cmd end @@ -233,10 +233,7 @@ function M.exec(cmd, opts) opts = opts or {} local proc = M.spawn(cmd, opts) proc:wait() - if proc.code ~= 0 then - error("Process failed with code " .. proc.code) - end - return vim.split(proc.data, "\n") + return vim.split(proc.data, "\n"), proc.code end return M diff --git a/lua/lazy/util.lua b/lua/lazy/util.lua index d1ae7fd..fed140c 100644 --- a/lua/lazy/util.lua +++ b/lua/lazy/util.lua @@ -162,12 +162,21 @@ end ---@param opts? LazyCmdOptions|{filetype?:string} function M.float_cmd(cmd, opts) opts = opts or {} + local Process = require("lazy.manage.process") + local lines, code = Process.exec(cmd, { cwd = opts.cwd }) + if code ~= 0 then + M.error({ + "`" .. table.concat(cmd, " ") .. "`", + "", + "## Error", + table.concat(lines, "\n"), + }, { title = "Command Failed (" .. code .. ")" }) + return + end local float = M.float(opts) if opts.filetype then vim.bo[float.buf].filetype = opts.filetype end - local Process = require("lazy.manage.process") - local lines = Process.exec(cmd, { cwd = opts.cwd }) vim.api.nvim_buf_set_lines(float.buf, 0, -1, false, lines) vim.bo[float.buf].modifiable = false return float