From cf0bfad049de897e672a4261a580b4cd5b93807e Mon Sep 17 00:00:00 2001 From: whosit Date: Sat, 22 Mar 2025 04:00:27 +0300 Subject: [PATCH] fix a comment and clarify the error handler func a bit --- using_xpcall.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/using_xpcall.lua b/using_xpcall.lua index 96d656e..63fb9e3 100644 --- a/using_xpcall.lua +++ b/using_xpcall.lua @@ -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)