rust-impl-error-handling
Installation
SKILL.md
rust-impl-error-handling
Recoverable errors are values: Result<T, E> flows through the call graph, the ? operator early-returns on Err with an automatic From conversion, and a well-designed error type implements Display + std::error::Error (or core::error::Error in no_std). Panic is reserved for programmer bugs, not for expected failure modes.
Cross-references: [[rust-errors-thiserror-anyhow]] (library vs application error-crate choice), [[rust-errors-runtime]] (panic mechanics, unwind vs abort), [[rust-errors-build-link]] (compile-time error decoding), [[rust-syntax-pattern-matching]] (matching on Result and Option).
When to use this skill
- User writes
.unwrap()or.expect()in library code. - User asks "should this return
ResultorOption". - User asks "why does
?not compile" or getsE0277: the trait From<X> for Y is not implemented. - User designs a new error type and chooses between
enumandstruct. - User asks about
core::error::Errorvsstd::error::Error. - User wants to chain errors with a
source(cause) pointer. - User asks "should I panic here, or return
Result". - User looks for
Resultcombinators (map,map_err,and_then,or_else,ok_or).