DEV Community

Write Errors That Don't Make Me Think

swyx on November 19, 2020

There is nothing more frustrating than a cryptic error message. When something goes wrong, chances are you already knew it - all a cryptic error ...
Collapse
 
dtinth profile image
Thai Pangsakulyanont • Edited

This is a really great post for referencing. Thanks for writing it!

For a really great example, I think the TypeScript compiler really gets it right, especially on the SEO:

I was pleasantly surprised when I saw that they even included this very specific error “error TS1185: Merge conflict marker encountered.”. Most other parsers gave a more generic message, such as “Unexpected token '<<'” (Chrome) or “Unexpected token” (Babel, although to its credit it also includes the relevant lines from the source code).

Collapse
 
swyx profile image
swyx

thanks Thai!

yeah the TS errors are next level... did you know they are even separated out for i18n? so they may have multiple error codes for the same English message just because it translates to different texts in other languages. i learned that from Orta's livestream.

Collapse
 
dtinth profile image
Thai Pangsakulyanont

😱 Whoa, that's really next level. Never knew that, thanks for mentioning it!

Collapse
 
_bkern profile image
Barry

I can't agree more. People fail to design errors and exceptions way too much. It is not as exciting as perhaps 'other' development but just as important. Another area I feel people don't spend enough time on is their domain modeling but that doesn't exactly fit this scenario. However, take this advice to heart and the more thought and design you put into these areas the better your code or app or library will be! If I could add one it would be to make errors unique. I hate when you encounter a library/codebase/app that returns the same 'error' for every scenario. Of course everything could have a valid reason (hopefully not that you just don't care about your error design) but the more you can guide the user or consumer the better.

Collapse
 
swyx profile image
swyx

thanks Barry! absolutely, that is a sign of lazy developers. of course, even better if the error has an error code. all in service of "Error SEO" :)