rust-errors

Design Rust error handling with thiserror and anyhow for libraries and applications.

Updated Apr 21, 2026
One-click install
npx skills add https://github.com/gregoryraymond/claude-agents-and-skills --skill rust-errors-gregoryraymond
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-errors
Source: https://github.com/gregoryraymond/claude-agents-and-skills/tree/main/skills/rust-errors
Command: npx skills add https://github.com/gregoryraymond/claude-agents-and-skills --skill rust-errors-gregoryraymond

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps Rust developers design robust error handling by separating language mechanics (Result, Option, ?, panic) from domain strategy (retry backoff, context, and user-facing vs internal errors).

Core Features & Use Cases

  • Error taxonomy: distinguish validation, transient, permanent, and internal errors with typed enums using thiserror and anyhow.
  • Context propagation: preserve error context across layers with thiserror::Error and anyhow::Context.
  • Domain-level strategies: guidance on retry, backoff, circuit breakers, and fallbacks for applications and libraries.

Quick Start

Create a small Rust project that propagates errors with Result and Option, and adds context using 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 structure Rust error handling for a library crate versus an application?

Rust error handling architecture differs by context: library crates need typed enums with thiserror for structured error types, while applications use anyhow for flexible context propagation and domain-level strategies like retry and backoff.

When should I use thiserror vs anyhow in Rust?

Use thiserror when defining structured error types for library crates that require specific error categories and From conversions. Use anyhow in application binaries when you need flexible context propagation across layers without strict error taxonomy.

What is the best way to classify transient and permanent errors in Rust?

Classify Rust errors by category—validation, transient, permanent, and internal—using typed enums. This taxonomy guides domain-level strategies such as retry, backoff, and circuit breakers for transient errors while failing fast on permanent ones.

How do I preserve error context across layers in Rust?

Preserve Rust error context across architectural layers by applying anyhow::Context to add domain-specific information to Result types, ensuring errors carry meaningful context as they propagate through validation and internal processing boundaries.

Can I implement retry and backoff strategies using Rust Result and Option?

Yes, domain-level retry and backoff strategies build on Rust Result and Option by classifying errors as transient before retrying, implementing exponential backoff for transient failures, and returning permanent errors immediately without retry attempts.

How do I separate user-facing errors from internal errors in Rust?

Separate user-facing Rust errors from internal errors by creating distinct error taxonomy categories within typed enums, ensuring internal errors contain debug context while user-facing errors expose clear, safe messages through proper From conversions.