Guides Rust error-handling choices between Result, Option, panic, thiserror and anyhow.
- What it does
- This instruction-only skill provides a decision framework for Rust error handling. It helps an agent decide whether a failure is expected or a bug, then choose between Result, Option, panic, thiserror and anyhow. It includes quick-reference tables, a decision flowchart, common errors, anti-patterns and pointers to related skills.
- When to use it
- Use it when writing or reviewing Rust code that involves Result, Option, ?, unwrap, expect, panic, anyhow or thiserror. It is meant for questions about when to panic versus return a Result, how to propagate errors with context, and how to design custom error types.
- Requirements
- No scripts or runtime dependencies; it is instructions only. It references Rust crates thiserror and anyhow as topics, but does not require them to be installed.
Error Handling
Layer 1: Language Mechanics
Core Question
Is this failure expected or a bug?
Before choosing error handling strategy:
- Can this fail in normal operation?
- Who should handle this failure?
- What context does the caller need?
Error → Design Question
Thinking Prompt
Before handling an error:
-
What kind of failure is this?
- Expected → Result<T, E>
- Absence normal → Option<T>
- Bug/invariant → panic!
- Unrecoverable → panic!
-
Who handles this?
- Caller → propagate with ?
- Current function → match/if-let
- User → friendly error message
- Programmer → panic with message
-
What context is needed?
- Type of error → thiserror variants
- Call chain → anyhow::Context
- Debug info → anyhow or tracing
Trace Up ↑
When error strategy is unclear:
Trace Down ↓
From design to implementation:
Quick Reference
Library vs Application
Decision Flowchart
Common Errors
Anti-Patterns
Related Skills