zhanghandong avatar

M06 Error Handling

The m06-error-handling skill teaches Rust developers how to choose appropriate error handling strategies by distinguishing between expected failures, normal absence, and bugs—using Result, Option, panic, and crates like thiserror and anyhow. It's designed for developers writing both library and application code who need to decide when to propagate errors, return Options, panic, or add context to failures. The skill solves the problem of unclear error handling decisions by providing a decision framework that traces back to domain design and down to specific implementation patterns.

skills.sh installs
827
GitHub stars
1.3K
last updated
Jul 14, 2026

Install

$ npx -y skills add zhanghandong/rust-skills --skill m06-error-handling --agent claude-code

Installs into .claude/skills of the current project.

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

Sponsors

Details

Repository
github.com/zhanghandong/rust-skills
Categories
Debugging, Rust

More from zhanghandong/rust-skills

All 34

Recommended

More Debugging
1codexstar69 avatarbug-huntercodexstar69/bug-hunterAdversarial bug hunting with a sequential-first pipeline (Recon, Hunter, Skeptic, Referee) that can optionally use safe read-only parallel triage. Scans without823skills.sh installs
2joellewis avatarperformance-metricsjoellewis/finance_skillsEvaluate investment performance on a risk-adjusted basis using industry-standard ratios and capture analysis. Use when the user asks about Sharpe ratio, Sortino746skills.sh installs
3dimillian avatarbug-hunt-swarmdimillian/skillsParallel read-only multi-agent root-cause investigation for bugs, regressions, crashes, flaky behavior, or unexplained failures. Use when the user asks to inves742skills.sh installs
4zhanghandong avatarm13-domain-errorzhanghandong/rust-skillsm13 domain error738skills.sh installs
5joellewis avatarperformance-reportingjoellewis/finance_skillsGenerate clear, accurate performance reports for investment portfolios with benchmarks, attribution, and risk dashboards. Use when the user asks about portfolio729skills.sh installs
6joellewis avatarperformance-attributionjoellewis/finance_skillsDecompose portfolio returns into explainable components to identify where value was added or lost. Use when the user asks about Brinson attribution, allocation 705skills.sh installs