Stack traces are useful if you want to work out the location of an error, but often they don't tell the whole story. I tend to find that this style of error message, with a one-line description & a stack trace, could be greatly improved upon. I have a few examples of what I mean;
Elm have a great blog post on what they call "Compiler Errors for Humans". They replace opaque errors with friendly, actionable advice & contextual hints, and this is probably one of my favourite examples of how to improve upon a one-line error message & stack trace.
sub levenshtein {}
levestein;
# ===SORRY!=== Error while compiling /home/zoffix/test.p6
# Undeclared routine:
# levestein used at line 2. Did you mean 'levenshtein'?
Similarly, Perl 6 use the Levenshtein algorithm to suggest replacements for undefined variables/methods (more on their blog post)
Like the Perl example, Dotty (a Scala compiler) has helpful examples and offers a more verbose output when you run it with the -explain flag. Worth a look: scala-lang.org/blog/2016/10/14/dotty-errors.html
Rust's blog post shows another example of using an --explain flag to provide further information about any given error:
> rustc --explain E0200
Unsafe traits must have unsafe implementations. This error occurs when an
implementation for an unsafe trait isn't marked as unsafe. This may be resolved
by marking the unsafe implementation as unsafe.
struct Foo;
unsafe trait Bar { }
// this won't compile because Bar is unsafe and impl isn't unsafe
impl Bar for Foo { }
// this will compile
unsafe impl Bar for Foo { }
One of the best examples I've seen in Node is a commit to Phenomic which adds more detail to a somewhat vague error; this was a frustrating message because it wouldn't show up in development, only when the site was built. However, adding the example to the message helps the developer experience out immensely:
github.com/MoOx/phenomic/releases/tag/0.20.3
I'm including Eve here because I think that it's important to show errors in close proximity with the code. Eve is a combined programming language and IDE, which is worth exploring if you have some time to spare. They have a good example of what an error looks like on their home page.
Do you have any great examples of well-designed error messages or language features which make errors more dev-friendly? I'd love to hear about them!
Is there anything like this for java? I am suffering here :D
I remember one time I found an error message in a program which went something like:
Ahhhhh my little brother won't stop playing [some annoying song title here]!!!! Someone shoot me!
it was hilarious.
Anuj Sharma
Co-founder at Appther.com | NodeJs | AngularJs | NoSql | MySql | Ionic |Next Generation APIs Developer.
Keyboard not found. Please press F1 button. :) ;)