Error Handling FAQ #50
Description
Reducing confusion around error handling in the rust-lang ecosystem is one of the top priorities for the error handling project group this year. As part of that effort we're going to start maintaining a list of Frequently Asked Questions about error handling.
For now this issue will serve as a living document for these FAQs, though eventually I hope to move them to a move permanent / visible location.
Unanswered Questions
If you have any questions that aren't covered by this list, or if you feel any of the answers here fail to completely answer their question for you please let us know so we can improve this list. You can follow up the following ways:
- Leave a comment on this issue
- Open a new topic in the project-error-handling zulip: https://rust-lang.zulipchat.com/#narrow/stream/257204-project-error-handling
- Schedule a meeting with me directly: https://calendly.com/yaahc/rust-libs-error-handling-office-hours
Frequently Asked Questions
When should I use panic!
vs Result
?
- Short Answer: Use the
panic!
macro to construct errors which signal that bug has been detected in the program, useResult::Err
to wrap error types that represent anticipated runtime failure modes in a correct program. - Long Answer(s)
- This is documented more thoroughly in the docs on the
panic!
macro: https://doc.rust-lang.org/nightly/std/macro.panic.html#when-to-use-panic-vs-result
- This is documented more thoroughly in the docs on the
- Related Improvements
Proposed Questions
How should I structure my error types?
TODO (complex and situational)
My current plan is to do a series of case studies on user codebases in various domains. If you have a codebase that you think would be a good candidate for a case study, either because you feel it has optimal error handling that should be used as an ideal example or because it needs improvement, please reach out so I can add you to the list of potential candidates.
- Requirements:
- must be able and willing to test nightly or experimental features when relevant, e.g. generic member access, try traits, error in panic, etc (tho you don't need to be willing to commit changes to master or anything)
- maintainers must have time to spare to provide feedback at multiple stages of the case study
There are many different error handling libraries in use, such as quick-error, error-chain, failure, snafu, thiserror, anyhow, and eyre. [I'm just listing those in the order in which I think they were released.] How do they differ? What different use-cases do they target?
TODO
- update error handling library section in awesome-rust, cross link to it, provide a framing around "types of error handling" that libraries provide support for (e.g. error defining vs error reporting) and tag the libraries in awesome-rust with the types of error handling they support.
- Possibly also link to relevant categories on
crates.io
andlib.rs
for further looking up available error handling libraries.