m06-error-handling
CRITICAL: Use for error handling. Triggers: Result, Option, Error, ?, unwrap, expect, panic, anyhow, thiserror, when to panic vs return Result, custom error, error propagation, 错误处理, Result 用法, 什么时候用 panic
Security Assessment
About m06-error-handling
This skill is a decision-oriented reference for error handling in Rust, part of the actionbook "rust-skills" module set (module m06, "Layer 1: Language Mechanics"). It exists to stop developers from reflexively reaching for `unwrap()` or `Box<dyn Error>` and instead reframes each error as a design question: is this failure expected or a bug, who should handle it, and what context does the caller need? Rather than prescribing a single fix, it maps common situations to the right construct so error handling reflects intent.
The SKILL.md provides thinking prompts, decision flowcharts, and quick-reference tables that route choices between `Result<T, E>`, `Option<T>`, the `?` operator, `panic!`/`assert!`, and the `thiserror` (library) versus `anyhow` (application) crates. It includes "trace up" guidance to related domain modules and "trace down" guidance to concrete implementations, plus tables of common errors and anti-patterns. A companion `examples/library-vs-app.md` walks through library error types with `thiserror`, application error handling with `anyhow` and `.context()`, layered error design, HTTP/CLI examples, and tests for error cases.
It targets intermediate Rust developers and teams who want consistent, idiomatic error strategy across libraries and applications. Typical use cases include deciding when to panic versus return a Result, designing typed error variants for a public crate boundary, adding context during propagation, and reviewing code for error-handling anti-patterns. The description also carries Chinese-language trigger phrases, signalling bilingual discoverability.
FAQ
What does this skill actually provide?
A reference SKILL.md plus an examples file. It offers decision tables, flowcharts, and thinking prompts for choosing Rust error-handling constructs; it does not ship runnable tooling or code that it executes on your behalf.
When should I use Result versus Option versus panic?
The skill's decision flowchart maps expected recoverable failures to Result<T, E>, normal absence to Option<T>, and bugs or invariant violations to panic!/assert!/unreachable!.
Does it recommend thiserror or anyhow?
Both, contextually: thiserror for typed errors at library boundaries so consumers can match on variants, and anyhow for ergonomic error handling with context inside applications.
Is any Rust experience assumed?
Yes. It assumes familiarity with Rust's Result/Option types and the ? operator, and is aimed at developers refining their error-handling strategy rather than absolute beginners.
Is the content available in languages other than English?
The trigger description includes Chinese phrases (for example 错误处理), but the body of the guidance itself is written in English.
Install m06-error-handling
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
actionbook/rust-skills