Improve error logging and reporting #3920
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Users have a hard time investigating errors to fix issues with their mod selections. Currently error messages hint to open up
client.log
, but only if the user is actively modding. Novice modders not using a debugger would see that hint, but would not know how to do that without reading the FAQ here on our wiki. Normal users would only see errors reported if they are thrown during mod loading.This PR aims to improve error reporting to further facilitate users self-diagnosing issues.
Repeated Errors
Current behavior is to report an error only once. This behavior hides the severity of some issues. Code has been added to track how many times a specific error has been encountered. Errors will be logged at 1, 10, and 100 repetitions, with 10 and 100 reports escalating to
Error
status and having an accompanying "The following exception has been repeated 100 times:" message.ModExceptionDiagnostics window
As the
UIModNetDiagnostics
window suggests the "health" of a mod's networking usage, aUIModExceptionDiagnostics
window would suggest the "health" of a mod's code. User can press F8 a few times to arrive at this menu, allowing them to quickly appraise the health of a mod. This window will show errors accumulating in real time, making it even better than using thetail
command or constantly reloading the client.log file. This is especially true for errors that will be omitted from client.log because they are repeats. Users can open the window and repeat a gameplay action that seems to be buggy or laggy. They will be able to immediately see the error count for the buggy mod increasing, suggesting which mod is causing the unexpected behavior.TODO: This window can be augmented with additional counters for "ignored" exceptions and for displaying the most recent exception or a listing of all exceptions, whatever is deemed useful.
NVIDIA_Share_2023-11-06_14-48-34.mp4
Open up logs folder directly (TODO)
Users don't know hot to get to client.log. We should provide a way to quickly open the logs folder or the specific log file.
One option is to for clicking on the "see client.log for full trace" message to open client.log directly.
Another option is adding a 馃摐 button on the main menu to open the logs folder.
Ignored Exceptions (TODO)
We allow modders to silence specific exceptions via
Logging.IgnoreExceptionSource/IgnoreExceptionContents
. This is useful for handling known exceptions, but it could be misused by modders, preventing effective troubleshooting by users.At the very least, it would be useful to log these additions: "System.InvalidCastException added to exception ignore list by ExampleMod". It might be useful to provide a "verbose" mode via a command line parameter that would ignore all of these filters, just in case a specific bug is not being reported properly in logs. Another thought is to track these exceptions and report them in the ModExceptionDiagnostics window, explained in another section.
Console
The console is not visible for normal client gameplay after launching, but it would be visible when doing host and play once #2705 is fixed. It is visible when debugging tModLoader itself as well. The colors can be adjusted.
Colors have been added for info/debug/warn/error: