From e49ee67ecc1fe57bdd966b40d66f84be2f6eda45 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 10 Aug 2023 11:17:19 +0300 Subject: [PATCH] refactor: throw errors in more lua way, i think --- lua/gopher/gotests.lua | 5 ++--- lua/gopher/iferr.lua | 3 +-- lua/gopher/struct_tags.lua | 4 +--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index a2386d8..94574ad 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -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 diff --git a/lua/gopher/iferr.lua b/lua/gopher/iferr.lua index 6213d3b..3797d25 100644 --- a/lua/gopher/iferr.lua +++ b/lua/gopher/iferr.lua @@ -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) diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index 0ffe114..16742d8 100644 --- a/lua/gopher/struct_tags.lua +++ b/lua/gopher/struct_tags.lua @@ -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,