-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy patherror.lua
More file actions
32 lines (25 loc) · 691 Bytes
/
error.lua
File metadata and controls
32 lines (25 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local notify = require('java-core.utils.notify')
local log = require('java.utils.log')
local function table_tostring(tbl)
local str = ''
for _, v in ipairs(tbl) do
str = str .. '\n' .. tostring(v)
end
return str
end
---Returns a error handler
---@param msg string messages to show in the error
---@return fun(err: any) # function that log and notify the error
local function get_error_handler(msg)
return function(err)
local trace = debug.traceback()
local log_obj = { msg }
table.insert(log_obj, err)
table.insert(log_obj, trace)
local log_str = table_tostring(log_obj)
log.error(log_str)
notify.error(log_str)
error(log_str)
end
end
return get_error_handler