Catcher - better errorhandler implementation and debugging utilities
Posted: Thu Jul 28, 2022 10:58 am
Catcher (tried to keep in line with LOVE library naming conventions ) is a currently small library that primarily implements a replacement for love.errorhandler, since I find it a bit lacking (I think it's been neglected in general). The default function displays the error message and traceback, but I always found debug.traceback's results a little hard to read, due to all the irrelevant information.
This replacement limits the shown stack frames to only relevant information (this is actually slightly variable, since you can pass in an offset to the builder function), from the error/assert call up to just below love.run (this might cause issues if you're testing a love.run implementation). Additionally, Catcher lets you move up and down the stack to inspect a frame's locals, there was a lot of pain involved in getting parameters ordered correctly, especially taking varargs into account.
The formatting isn't perfect, notably if a frame is too long (wraps), the cursor column won't align with it anymore, but line wrapping works fine with error messages and locals. You can also pass the builder function a custom_fmt table to change certain aspects of the result, in the attached screenshot, clear_color is set to black.
It tries to be similar to the default function controls-wise, retaining ctrl-c to copy and escape to exit, but also provides the stack cursor and ctrl-t to start the console debugger (can also be swapped out for a custom function).
Here's an example usage, with the default arguments:
Eventually I want to a add profiler using jit.profile (especially since I couldn't find any existing ones), but that's something for another day right now.
This replacement limits the shown stack frames to only relevant information (this is actually slightly variable, since you can pass in an offset to the builder function), from the error/assert call up to just below love.run (this might cause issues if you're testing a love.run implementation). Additionally, Catcher lets you move up and down the stack to inspect a frame's locals, there was a lot of pain involved in getting parameters ordered correctly, especially taking varargs into account.
The formatting isn't perfect, notably if a frame is too long (wraps), the cursor column won't align with it anymore, but line wrapping works fine with error messages and locals. You can also pass the builder function a custom_fmt table to change certain aspects of the result, in the attached screenshot, clear_color is set to black.
It tries to be similar to the default function controls-wise, retaining ctrl-c to copy and escape to exit, but also provides the stack cursor and ctrl-t to start the console debugger (can also be swapped out for a custom function).
Here's an example usage, with the default arguments:
Code: Select all
love.errorhandler = require("catcher").errorhandler({
frame = " %name:%currentline @ (%short_src:%linedefined)\n",
lclvar = "\t%name = %value\n",
clear_color = {89/255, 157/255, 220/255},
text_color = {1, 1, 1},
text_size = 14,
inset = 70
}, debug.debug, 0, nil)