m06-error-handling

Teach Rust error-handling patterns for Result, Option, and typed errors.

Updated Jan 21, 2026
One-click install
npx skills add https://github.com/lywa1998/self-host-claude-marketplace --skill m06-error-handling-lywa1998
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m06-error-handling
Source: https://github.com/lywa1998/self-host-claude-marketplace/tree/main/plugins/rust-skills/skills/m06-error-handling
Command: npx skills add https://github.com/lywa1998/self-host-claude-marketplace --skill m06-error-handling-lywa1998

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust error handling can be verbose and error-prone; this Skill guides you in choosing between Result, Option, and panics, designing robust error types, and propagating context effectively.

Core Features & Use Cases

  • Guidance on when to use Result vs Option vs panic in Rust applications and libraries.
  • Patterns for propagating errors with context using thiserror and anyhow.
  • Techniques for designing typed error enums, source chaining, and ergonomic error handling across layers (library, service, application).
  • Real-world scenarios including IO errors, parsing failures, and domain-specific error propagation.

Quick Start

Identify a Rust function that returns Result and add contextual information to the error path to demonstrate improved debuggability.

Frequently Asked Questions about m06-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors in Rust using Result and Option effectively?

Rust error handling with Result and Option requires choosing between recoverable errors and optional values. Use Result for fallible operations like IO or parsing, and Option when a value may be absent without indicating a failure.

When should I use panic versus returning a Result in Rust applications?

Use panic in Rust for unrecoverable states or violated invariants, and return a Result for expected recoverable failures like IO errors or parsing failures. Correct panic versus return strategies ensure robust domain error propagation across application layers.

What is the best way to propagate errors with context in Rust using thiserror and anyhow?

Propagating errors with context in Rust is best achieved using thiserror for typed library errors and anyhow for application-level error chains. This combination provides ergonomic error handling and rich contextual messages across architectural layers.

How do I design typed error enums with source chaining in Rust libraries?

Designing typed error enums in Rust involves defining custom error types using thiserror, implementing source chaining to wrap underlying causes, and creating ergonomic error handling across library, service, and application layers for improved debuggability.

Does thiserror work well for domain-specific error propagation across library and application layers?

Yes, thiserror works well for domain-specific error propagation by enforcing typed errors with contextual messages. It integrates effectively across library and application codebases to handle IO, parsing, and domain-specific errors with structured source chaining.