rust-errors

Designs Rust error handling with Result, thiserror, anyhow, and recovery patterns.

3|Updated Aug 8, 2026
One-click install
npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-errors-jose-polanco-oxte
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-errors
Source: https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer/tree/main/.agents/skills/rust/sub-skills/rust-errors
Command: npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-errors-jose-polanco-oxte

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rust developers often struggle to choose between Result, Option, and panic, pick the right error crate, and build resilient recovery logic. This Skill provides decision frameworks and idiomatic patterns for error handling in Rust libraries and applications. ## Core Features & Use Cases - Error Type Decisions: Guides the choice between Result, Option, and panic based on whether failures are recoverable domain errors or defects. - Crate Selection & Design: Explains when to use thiserror for typed library errors versus anyhow for application-level context, including #[from], #[source], and error layering. - Resilience Patterns: Covers retry with exponential backoff and jitter, timeouts, fallback, and circuit breakers, with failure classification (transient vs permanent). - Use Case: When building a Rust web service, use this Skill to design a typed StorageError enum with thiserror, propagate it with ?, add context with anyhow at the app boundary, and map errors to HTTP responses. ## Quick Start Ask the AI to design error handling for a Rust function that reads and parses a config file, choosing between thiserror and anyhow.

Frequently Asked Questions about rust-errors

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

FAQPage Schema
How do I choose between thiserror and anyhow in Rust?

Use thiserror for libraries, where callers need typed error enums they can match on. Use anyhow for applications, where you only need to add context and report errors. Mixing is normal: libraries return typed errors and the app collects them into anyhow.

When should I use Result vs Option vs panic in Rust?

Use Result when an operation can fail in normal operation and the caller must decide. Use Option when absence is normal and carries no reason. Use panic only for violated invariants or programmer bugs that are not recoverable.

Is unwrap() acceptable in production Rust code?

No, unwrap() on a reachable production path is a bug because it panics with no context. Prefer expect() with a message when a panic is genuinely justified, or return Result and propagate with ?. unwrap is fine in tests, benches, and examples.

How do I add context to errors in Rust with anyhow?

Use anyhow's context() or with_context() methods to attach descriptive messages at boundaries. Prefer with_context with a closure when the message allocates, and include the failing value like a path or ID rather than generic strings.

How do I implement retry with backoff in Rust?

Retry only transient failures with exponential backoff, jitter, and an attempt cap. You can hand-roll a loop with tokio sleep or use the backon crate with ExponentialBuilder and a when() predicate gated on your error's is_transient() classification.

When should I not retry a failed operation in Rust?

Never retry permanent errors like 404s, validation failures, or auth errors, and avoid retrying non-idempotent operations without an idempotency key. Unbounded retries without a cap or timeout can turn a small failure into an outage.