error-docs
error-docs copied to clipboard
Case studies
I want to add some case studies to the error design section. Ideas:
- compiler/parser errors
- a prototype library
- a library with network client or something
- a CLI app
In case it's helpful, we (the AWS SDK for Rust team) just put a lot of thought into how we expose errors to users of our libraries. @jdisanti wrote an RFC that you can read here.
John put forth the following goals:
- Errors are forwards compatible, and changes to errors are backwards compatible
- Errors are idiomatic and ergonomic. It is easy to match on them and extract additional information for cases where that's useful. The type system prevents errors from being used incorrectly (for example, incorrectly retrieving context for a different error variant)
- Error messages are easy to debug
- Errors implement best practices with Rust's Error trait (for example, implementing the optional source() function where possible)
An we ended up dividing 99% of our existing errors into two categories:
- Actionable: Errors that can/should influence program flow; where it's useful to do different work based on additional error context or error variant information
- Informative: Errors that inform that something went wrong, but where it's not useful to match on the error to change program flow