fix a comment and clarify the error handler func a bit
This commit is contained in:
parent
11ee6df95c
commit
cf0bfad049
@ -53,6 +53,7 @@ end
|
||||
local function error_printer(err)
|
||||
log_add(err)
|
||||
log_add(debug.traceback("----------------------", 2))
|
||||
return "error was logged"
|
||||
end
|
||||
|
||||
|
||||
@ -159,9 +160,10 @@ core.register_chatcommand(
|
||||
)
|
||||
|
||||
-- This version allows us to get the error stack trace. We get the
|
||||
-- trace by passing our helper function `error_printer` to xpcall.
|
||||
-- (`error_printer` will be called on error without unwinding the
|
||||
-- stack, so we can call `debug` functions to examine the error).
|
||||
-- trace by passing error handler function `error_printer` to xpcall.
|
||||
-- (our helper funciton, `error_printer` will be called on error
|
||||
-- without unwinding the stack, so we can call `debug` functions to
|
||||
-- examine the error).
|
||||
core.register_chatcommand(
|
||||
"bugged_safe2",
|
||||
{
|
||||
@ -170,7 +172,11 @@ core.register_chatcommand(
|
||||
-- NOTE: if this does not work, you may need to make sure you're using luajit or newer lua
|
||||
local status, ret1, ret2 = xpcall(bugged, error_printer, playername, params)
|
||||
-- `status` will be `false` if function call raised an error
|
||||
-- `ret1` will contain the error message on error, or first returned value on no errors
|
||||
|
||||
-- `ret1` will contain first returned value in case of no
|
||||
-- errors, or, in case of error, the value returned by the
|
||||
-- error handler function.
|
||||
|
||||
-- `ret2` will contain second returned value on no errors
|
||||
-- etc.
|
||||
return status, string.format("%s | %s", ret1, ret2)
|
||||
|
Loading…
Reference in New Issue
Block a user