refactor: throw errors in more lua way, i think

This commit is contained in:
Smirnov Oleksandr 2023-08-10 11:17:19 +03:00
parent 640a36a7f2
commit e49ee67ecc
3 changed files with 4 additions and 8 deletions

View file

@ -12,8 +12,7 @@ local function add_test(args)
args = args,
on_exit = function(data, status)
if not status == 0 then
vim.notify("gotests failed: " .. data, vim.log.levels.ERROR)
return
error("gotests failed: " .. data, vim.log.levels.ERROR)
end
vim.notify("unit test(s) generated", vim.log.levels.INFO)
@ -25,7 +24,7 @@ end
function gotests.func_test()
local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
if ns == nil or ns.name == nil then
vim.notify("cursor on func/method and execute the command again", vim.log.levels.INFO)
vim.notify("cursor on func/method and execute the command again", vim.log.levels.WARN)
return
end

View file

@ -8,8 +8,7 @@ function iferr.iferr()
local data = vim.fn.systemlist((c.iferr .. " -pos " .. boff), vim.fn.bufnr "%")
if vim.v.shell_error ~= 0 then
vim.notify("iferr failed: " .. data, vim.log.levels.ERROR)
return
error("iferr failed: " .. data, vim.log.levels.ERROR)
end
vim.fn.append(pos, data)

View file

@ -1,7 +1,6 @@
local ts_utils = require "gopher._utils.ts"
local r = require "gopher._utils.runner"
local c = require("gopher.config").commands
local u = require "gopher._utils"
local struct_tags = {}
local function modify(...)
@ -56,10 +55,9 @@ local function modify(...)
or tagged["start"] == nil
or tagged["start"] == 0
then
u.deferred_notify("failed to set tags " .. vim.inspect(tagged), vim.log.levels.ERROR)
error("failed to set tags " .. vim.inspec(tagged), vim.log.levels.ERROR)
end
-- write goted tags
vim.api.nvim_buf_set_lines(
0,
tagged.start - 1,