Unique Error Code
Often overlooked, but very necessary for non-English speakers like me.
Many problems have been solved in detail in mainstream languages, but localized errors are probably not solved in localized search engines.
And with a unified error code, you can use Rust "E0308"
to search for the cause of the error and the solution in other languages.
The error code also facilitates downgrading to C language FFI.
Where the Error Occurred
It is best to be a hyperlink, click to jump to the location where the error occurred, which is convenient for debugging.
The format is generally
mopno_project/sub_project/module/code.c:line:col
Note that whenever a path appears, it should be relative to the project root.
Otherwise, it is very easy to leak privacy or secrets.
When the Error Occurred
If it is a runtime error, show the event when the error occurred, using a human-friendly output form, such as RFC3339.
Why the Error Occurred and How to Fix
The main cause of the error needs to be given, so that the programmer can quickly understand the problem.
If possible, give possible fixes, or templates for fixes.
If it is an html environment like jupyter, it can support copying by click.
Simple internal errors IDE will usually prompt you to use quick-fix.
But if it is an external error, the IDE generally does not support automatic repair. For example, if there is a Regex syntax problem, then the library author needs to provide a repair solution.
This method is not as convenient as quick-fix
, but at least I haven't encountered a language that can use libraries to define IDE behavior.
Stack Backtrace
In debug mode a stack trace should be generated, printing each step of the call.
I think actually print
should also generate a stack trace in debug mode.
But the overhead is huge, so don't use it as the default behavior, and don't print it in release unless specified by the user.