rust-error-handling

Implements Rust error handling with Result, Option, thiserror, and anyhow patterns.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/luckyegg168/rust-skill --skill rust-error-handling-luckyegg168
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-error-handling
Source: https://github.com/luckyegg168/rust-skill/tree/main/rust-skills/rust-error-handling
Command: npx skills add https://github.com/luckyegg168/rust-skill --skill rust-error-handling-luckyegg168

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires thiserror, anyhow, color-eyre, and includes references (resource) components.

What problem does it solve? Rust developers often struggle to choose between Result and Option, propagate errors correctly with the ? operator, and decide between thiserror and anyhow, leading to fragile unwrap-heavy code and confusing compiler errors. ## Core Features & Use Cases - Error Strategy Guidance: Provides decision rules for choosing thiserror in library crates versus anyhow in application crates, plus when panic and unwrap are acceptable. - Custom Error Type Patterns: Shows thiserror 2.0 derive patterns with #[from] conversions, manual Error trait implementations, and multi-layer error enums mapped to API responses. - Error Propagation & Context: Demonstrates the ? operator, anyhow Context, bail!, ensure!, error chain traversal, and downcast-based recovery. - Use Case: When building a Rust service that loads config, connects to a database, and parses files, use this Skill to structure layered error types and attach context so failures produce clear, actionable error chains. ## Quick Start Ask the AI to refactor your Rust function that uses unwrap into proper Result-based error handling with thiserror or anyhow.

Frequently Asked Questions about rust-error-handling

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

FAQPage Schema
How do I handle errors in Rust with Result and the ? operator?▼

Return Result<T, E> from functions that can fail and use the ? operator to propagate errors automatically. The ? operator calls From::from to convert error types, so implement From or use #[from] with thiserror for compatible conversions.

Should I use thiserror or anyhow for Rust error handling?▼

Use thiserror for library crates where callers need to match on concrete error variants, and anyhow for application code where error kinds do not need distinguishing. Both can coexist: libraries use thiserror while the main binary uses anyhow.

Why does the ? operator fail with 'trait From is not implemented'?▼

This error occurs when ? tries to convert between incompatible error types. Fix it by implementing From<A> for B manually, adding #[from] in a thiserror enum, or converting explicitly with map_err before applying ?.

When is it acceptable to use unwrap or panic in Rust?▼

Unwrap is acceptable in tests, prototypes, and cases that are logically infallible with an expect message explaining why. Never use unwrap in a library's public API; return Result instead so callers can handle failures.

How do I convert Option to Result in Rust?▼

Use .ok_or(error) to convert an Option into a Result with a static error value, or .ok_or_else with a closure to construct the error lazily. This is useful when a missing value should be treated as a failure.