m06-error-handling

Design Rust error handling with Result, Option, thiserror, and anyhow.

1.4k|110|Updated Jan 17, 2026
One-click install
npx skills add https://github.com/actionbook/rust-skills --skill m06-error-handling-actionbook
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m06-error-handling
Source: https://github.com/actionbook/rust-skills/tree/main/skills/m06-error-handling
Command: npx skills add https://github.com/actionbook/rust-skills --skill m06-error-handling-actionbook

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust projects often struggle with designing robust error handling, including when to use Result or Option, how to define clear error types, and how to propagate rich context across layers. This skill provides a structured approach to error strategy, including domain-driven design, error propagation, and ergonomic messaging for libraries and applications.

Core Features & Use Cases

  • Domain-driven error design using thiserror for strong, typed error variants.
  • Context-rich propagation with anyhow::Context and proper source chaining.
  • Pattern guidance for converting between Option and Result and choosing appropriate wrappers (thiserror, thiserror::Error, From implementations).
  • Guidance for library vs application boundaries, testing error scenarios, and ergonomic user-facing messages.

Quick Start

Prompt the AI to evaluate a Rust function that reads a config file and returns Result<Config, AppError>, and propose an error type design and propagation strategy using thiserror and anyhow.

Frequently Asked Questions about m06-error-handling

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

FAQPage Schema
How do I design Rust error types for a library using thiserror?

Design Rust error types for a library using thiserror by defining strong, typed error variants that represent domain-specific failures. This approach ensures clear, structured error propagation across module boundaries and enables ergonomic handling for consumers.

When should I use anyhow versus thiserror in Rust error handling?

Use anyhow for application-level error handling to add rich context dynamically, and use thiserror for library design to expose structured, typed errors. This separation ensures ergonomic user-facing messages while maintaining strict type safety for library consumers.

What is the best way to propagate context across module boundaries in Rust?

The best way to propagate context across module boundaries in Rust is using anyhow::Context to attach rich messages and proper source chaining. This strategy maintains the full error stack trace across different layers of an application.

How do I convert between Option and Result in Rust error handling?

Convert between Option and Result in Rust error handling using pattern guidance to map None values to specific error types. This ensures robust error propagation by explicitly defining how missing values translate into structured failures.

Should I use panics or return Result for error handling in Rust libraries?

Return Result for expected, recoverable errors in Rust libraries to allow callers to handle failures gracefully, and reserve panics for unrecoverable state violations. This strategy ensures robust domain-driven error design and safe module boundaries.

Does this Rust error handling skill apply to both library and application code?

Yes, this Rust error handling skill applies to both library and application code. It provides pattern guidance for defining domain-driven error types and ergonomic user-facing messages across different architectural boundaries.