nrc / error-docs

Documentation of Rust error handling
Creative Commons Attribution 4.0 International
47 stars 4 forks source link

Case studies #1

Open nrc opened 1 year ago

nrc commented 1 year ago

I want to add some case studies to the error design section. Ideas:

Velfi commented 1 year ago

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:

  1. Errors are forwards compatible, and changes to errors are backwards compatible
  2. 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)
  3. Error messages are easy to debug
  4. 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: