More debug and error printing options#5457
Conversation
…or out of the color_table
…ror checking and handling.
…n error. Does not halt execution.
… and error to provide more information, including stacktrace, for your debug and error messages.
|
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
|
I... am not sure why it thinks it is grabbing the closest color changes as well. These were already merged before and shouldn't be showing up as diff either, I wouldn't think. |
|
clang-tidy review says "All clean, LGTM! 👍" |
|
There we go, that looks better. |
|
It's working fine for me! I really like this addition. The only thing I would say is that it would be nice to have more color in the messages using a scheme similar to what we already get from Mudlet errors- |
|
The problem with that is errorc is meant to be a more direct 1:1 of debugc, which doesn't include any of that kind of information. I'm then just using errorc to generate the messages for printError, except when haltExecution is specified, then it uses error. If I'd managed to find a decent example of lua_Debug in use (and not just the #&$ lutok wrapper code) I might have tried to implement printError and printDebug in C++ but without that trying to suss it out from scratch/docs would have doubled or more the time to write it for me. If you've got any insights/hints into how to make that happen or wanna try tackling it that'd be awesome, though. I'm not against implementing it all in C++ if it's not going to make it a 3 day task instead of the 1 day task it's already been. |
|
Could perhaps change errorc's behaviour such that the last argument supplied to it is the top of the stack/calling function info... IE the As it is right now both debugc and errorc combine their arguments into a single message and assigns them numbers. So I don't know how feasible it would be to change debugc now, but perhaps errorc could be different in this regard? I'm open to suggestions. |
|
I don't think it's important enough to warrant adding time before merge! It's genuinely great the way it is. |
|
I really like the improvement here, and while I haven't dived into the code just yet, I'm first just stepping back and looking at the thousand foot view which gives us:
Do we think that it's intuitive for someone new coming to know which function should be used when? |
|
I'm not sure if I think that's the right question. Someone new probably isn't going to know about handling errors at all, and someone who does know error handling is likely to start at the Mudlet wiki I think, where we can funnel people to printError and printDebug. Which I honestly think I personally will be using in place of debugc and error. It's a reasonable question, but I'm not sure if it applies here. At least I didn't go with Error and Debug? In all seriousness, I think they're useful enough to leave in, and any confusion the extra set of functions might cause we can smooth over with documentation and support. But given how few people coming in seem to even know debugc is a thing I'm not sure most of the people who would be confused by it will notice it. |
… formatting is more in line with the existing errors messages
|
PR updated, along with opening comment. In short:
|
|
hmm, is making some tests a bit problematic due to how I was spying on things. will look into that in a little bit |
…test' in order for tests to be able to spy on it.
|
Slight adjustment to allow errorc to stick around in the self-test profile has the tests passing again. Remains nil in other profiles not named "Mudlet self-test" |
| local showTrace = options.showTrace | ||
| local msg = options.msg or "" | ||
| local halt = options.halt | ||
| local stackTable = debug.traceback():gsub("\t", " "):gsub("%[string ",""):split("\n") |
There was a problem hiding this comment.
Could it be optimized to only retrieve the traceback if it's needed? Afaik it's not a cheap function
There was a problem hiding this comment.
if I can find another way of reliably determining what level of the stack to inspect for the function information, then yes. But I was not able to find that when I went looking. That being said, in testing just now it only took 0.022 seconds to run 1000 printDebug statements, so I'm not sure at 0.022 microseconds per printDebug it's adding significant overhead?


Brief overview of PR changes/additions
I use
debugca fair bit for printing information to the error console when I don't necessarily wish to halt execution, but either something has gone wrong or the information could be important for troubleshooting if they come looking for help.But I have always kind of wanted the ability to print a more urgent error to the console without necessarily halting execution, and that snowballed to wanting something a bit more robust as well for both debug and error messages.
Adds an internal only function, errorc, which allows for printing detailed errors messages.
On the back of errorc and debugc, adds the following functions in Lua which provide extended functionality
printDebug(msg, showTrace)
printError(msg, showTrace, haltExecution)
The following image shows
And the same, but from the main console
Altogether, from the error console in the script editor
Motivation for adding to Mudlet
I wanted to be able to register 'error' level messages without having to halt execution. And then I started thinking about all the information I usually want in such instances and decided to wrap the basic functionality to provide this information
Other info (issues closed, discussion etc)
I could not for the life of me figure out where the colors for printMessage were being set, so I used a color picker to match the r,g,b values. Open to suggestions on making this better, again focused on functionality to start.
After some feedback, this was changed to not expose errorc() to the user, but rather to use it as an entry point for printError. Since that is the case I rejiggered it a little bit to make it look more in line with the existing error messages.
Release post highlight
New functions printError and printDebug provide more information for debugging your scripts