1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 09:59:29 +00:00

Allow rewriting without new traceback

This commit is contained in:
Étienne Fildadut 2021-05-17 15:19:55 +02:00
parent a3f05f5046
commit f5752cd231
3 changed files with 5 additions and 5 deletions

View file

@ -597,7 +597,7 @@ Please note that Candran can only wrap code directly called from Candran; if an
If you want Candran to always wrap errors, you will need to wrap your whole code in a `xpcall`: `xpcall(func, candran.messageHandler)`. If you want Candran to always wrap errors, you will need to wrap your whole code in a `xpcall`: `xpcall(func, candran.messageHandler)`.
* ```candran.messageHandler(message)```: the error message handler used by Candran. Given `message` the Lua error string, returns full Candran traceback where soure files and lines are rewritten to their Candran source. You can use it as is in xpcall as a message handler. * ```candran.messageHandler(message[, noTraceback])```: the error message handler used by Candran. Given `message` the Lua error string, returns full Candran traceback where soure files and lines are rewritten to their Candran source. You can use it as is in xpcall as a message handler. If `noTraceback` is `true`, Candran will only rewrite `message` and not add a new traceback.
Also note that the Candran message handler will add a new, rewritten, stacktrace to the error message; it can't replace the default Lua one. You will therefore see two stacktraces when raising an error, the last one being the Lua one and can be ignored. Also note that the Candran message handler will add a new, rewritten, stacktrace to the error message; it can't replace the default Lua one. You will therefore see two stacktraces when raising an error, the last one being the Lua one and can be ignored.

View file

@ -265,8 +265,8 @@ end
--- Candran error message handler. --- Candran error message handler.
-- Use it in xpcall to rewrite stacktraces to display Candran source file lines instead of compiled Lua lines. -- Use it in xpcall to rewrite stacktraces to display Candran source file lines instead of compiled Lua lines.
function candran.messageHandler(message) function candran.messageHandler(message, noTraceback)
if not message:match("\nstack traceback:\n") then if not noTraceback and not message:match("\nstack traceback:\n") then
message = debug.traceback(message, 2) message = debug.traceback(message, 2)
end end
return message:gsub("(\n?%s*)([^\n]-)%:(%d+)%:", function(indentation, source, line) return message:gsub("(\n?%s*)([^\n]-)%:(%d+)%:", function(indentation, source, line)

View file

@ -6586,8 +6586,8 @@ else -- candran.can:260
return f() -- candran.can:262 return f() -- candran.can:262
end -- candran.can:262 end -- candran.can:262
end -- candran.can:262 end -- candran.can:262
candran["messageHandler"] = function(message) -- candran.can:268 candran["messageHandler"] = function(message, noTraceback) -- candran.can:268
if not message:match("\ if not noTraceback and not message:match("\
stack traceback:\ stack traceback:\
") then -- candran.can:269 ") then -- candran.can:269
message = debug["traceback"](message, 2) -- candran.can:270 message = debug["traceback"](message, 2) -- candran.can:270