Skip to content

Commit

Permalink
feat: defer_to_coroutine display error using vim.notify
Browse files Browse the repository at this point in the history
  • Loading branch information
idanarye committed Mar 21, 2024
1 parent a012961 commit aca9e3c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lua/moonicipal/util.lua
Expand Up @@ -7,27 +7,28 @@ function M.abort(msg)
end

function M.defer_to_coroutine(dlg, ...)
local args = {...}
local co = coroutine.create(function()
xpcall(dlg, function(error)
if type(error) == 'table' then
local abort_message = error[ABORT_KEY]
local co = coroutine.create(function(...)
xpcall(dlg, function(err)
if type(err) == 'table' then
local abort_message = err[ABORT_KEY]
if abort_message ~= nil then
if abort_message then
vim.api.nvim_err_writeln(abort_message)
end
return
end
end
if type(error) ~= 'string' then
error = vim.inspect(error)
if type(err) ~= 'string' then
err = vim.inspect(err)
end
local traceback = debug.traceback(error, 2)
local traceback = debug.traceback(err, 2)
traceback = string.gsub(traceback, '\t', string.rep(' ', 8))
vim.api.nvim_err_writeln(traceback)
end, unpack(args))
vim.notify(traceback, vim.log.levels.ERROR, {
title = 'ERROR in a "Days Without" related coroutine'
})
end, ...)
end)
coroutine.resume(co)
coroutine.resume(co, ...)
return co
end

Expand Down

0 comments on commit aca9e3c

Please sign in to comment.