feat(iferr): write error to log file if occur

This commit is contained in:
Smirnov Oleksandr 2024-06-15 12:10:13 +03:00
parent 36c686919c
commit 161b53d498

View file

@ -4,6 +4,7 @@
---@usage execute `:GoIfErr` near any err variable to insert the check ---@usage execute `:GoIfErr` near any err variable to insert the check
local c = require "gopher.config" local c = require "gopher.config"
local log = require "gopher._utils.log"
local iferr = {} local iferr = {}
-- That's Lua implementation: github.com/koron/iferr -- That's Lua implementation: github.com/koron/iferr
@ -14,6 +15,7 @@ function iferr.iferr()
local data = vim.fn.systemlist((c.commands.iferr .. " -pos " .. boff), vim.fn.bufnr "%") local data = vim.fn.systemlist((c.commands.iferr .. " -pos " .. boff), vim.fn.bufnr "%")
if vim.v.shell_error ~= 0 then if vim.v.shell_error ~= 0 then
error("iferr failed: " .. data) error("iferr failed: " .. data)
log.error("failed. output: " .. data)
end end
vim.fn.append(pos, data) vim.fn.append(pos, data)