actionbook avatar

M06 Error Handling

Decision guide for Rust error handling: choosing Result, Option, panic, thiserror, or anyhow.

skills.sh installs
3.8K
GitHub stars
1.6K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers when to use Result, Option, ? propagation, unwrap/expect, and panic, plus the library-versus-application crate choice
  • Includes a decision flowchart, a quick-reference table, common errors with fixes, and anti-patterns to avoid
  • Enforces the question "Is this failure expected or a bug?" before picking a strategy, and points to thiserror for libraries and anyhow for applications
  • Designed for Rust developers designing error types and propagation, with links to related domain and ecosystem skills

Install

$ npx -y skills add actionbook/rust-skills --skill m06-error-handling -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

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

PatternDon't Just SayAsk Instead
unwrap panics"Use ?"Is None/Err actually possible here?
Type mismatch on ?"Use anyhow"Are error types designed correctly?
Lost error context"Add .context()"What does the caller need to know?
Too many error variants"Use Box"Is error granularity right?

Thinking Prompt

Before handling an error:

  1. What kind of failure is this?

    • Expected → Result<T, E>
    • Absence normal → Option
    • Bug/invariant → panic!
    • Unrecoverable → panic!
  2. Who handles this?

    • Caller → propagate with ?
    • Current function → match/if-let
    • User → friendly error message
    • Programmer → panic with message
  3. What context is needed?

    • Type of error → thiserror variants
    • Call chain → anyhow::Context
    • Debug info → anyhow or tracing

Details

Repository
github.com/actionbook/rust-skills
Category
Rust
First seen
May 16, 2026

More from actionbook/rust-skills

All 38

Similar to M06 Error Handling

More Rust