rust-error-handling

Design canonical error structs and propagate errors with thiserror or anyhow.

Updated Apr 20, 2026
One-click install
npx skills add https://github.com/vincent119/ai-rules-kit --skill rust-error-handling-vincent119
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-error-handling
Source: https://github.com/vincent119/ai-rules-kit/tree/main/skills/rust-error-handling
Command: npx skills add https://github.com/vincent119/ai-rules-kit --skill rust-error-handling-vincent119

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust error handling can be verbose and error-prone; canonical patterns, clear propagation, and contextual messages reduce bugs and improve diagnostics.

Core Features & Use Cases

  • Canonical error struct patterns for library crates
  • Interoperability with thiserror and anyhow for ergonomic error handling
  • Contextual error propagation and rich diagnostics across library and application boundaries
  • Use cases include designing error types, propagating errors across layers, and improving user-facing error messages

Quick Start

Define a canonical error type in a library, and adopt thiserror or anyhow to propagate errors with context.

Frequently Asked Questions about rust-error-handling

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

FAQPage Schema
What's the best way to handle errors in a Rust library crate?

The best way to handle Rust library errors is by defining canonical error structs using thiserror, ensuring structured error types and clear propagation across boundaries. This reduces bugs and improves diagnostic messaging.

When should I use anyhow instead of thiserror for Rust error handling?

Use thiserror when designing distinct error types for library crates, and use anyhow for application code where you need ergonomic error propagation with contextual messages across layers without defining custom error enums.

How do I propagate errors with context across Rust application boundaries?

Propagate Rust errors with context by adopting anyhow or eyre to wrap errors with contextual messaging, ensuring rich diagnostics and safe recovery across library and application boundaries without relying on unwrap or expect.

Why should I avoid unwrap and expect in production Rust code?

Avoid unwrap and expect in production Rust code because they cause panics on unrecoverable failures. Structured error handling reserves panics for truly unrecoverable states and uses canonical error types for safe recovery and better diagnostics.

Can I use eyre with canonical Rust error types for better diagnostics?

Yes, you can use eyre alongside canonical Rust error types to enhance contextual error propagation and rich diagnostics, providing an ergonomic alternative to anyhow for application-level error handling and recovery.