rust-error-handling

Design Rust error hierarchies with thiserror and anyhow.

1|Updated Dec 30, 2025
One-click install
npx skills add https://github.com/gar-ai/mallorn --skill rust-error-handling-gar-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-error-handling
Source: https://github.com/gar-ai/mallorn/tree/main/.claude/skills/rust-foundation-error-handling
Command: npx skills add https://github.com/gar-ai/mallorn --skill rust-error-handling-gar-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps Rust developers design robust error hierarchies by leveraging thiserror for library code and anyhow for application code, enabling structured errors and rich context.

Core Features & Use Cases

  • Library patterns: derive errors with thiserror for typed, ergonomic error variants.
  • Application patterns: use anyhow to propagate errors with contextual messages.
  • Error propagation and hierarchy: compose domain-specific error types and conversions between layers.
  • Guidelines: ensure debugging friendly errors, use #[from] for conversions, and maintain clear error messages.

Quick Start

Write a small Rust crate that defines a custom error enum with thiserror and add context to an application function with 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 design structured error hierarchies in Rust?

Design structured error hierarchies in Rust by deriving custom error enums with thiserror for typed library variants and using anyhow to propagate runtime errors with contextual messages in application code.

When should I use thiserror vs anyhow for Rust error handling?

Use thiserror for library crates requiring typed, ergonomic error variants, and use anyhow for application code needing context-rich error propagation and ergonomic conversion paths between architectural layers.

How do I add context to error propagation in Rust applications?

Add context to error propagation in Rust applications by using anyhow to attach contextual messages during runtime error handling, enabling domain-specific error hierarchies and clear debugging-friendly error outputs.

How do I implement ergonomic error conversion paths in Rust libraries?

Implement ergonomic error conversion paths in Rust libraries by using the thiserror #[from] attribute to automatically generate From implementations, ensuring structured and testable error messages across domain layers.

Does thiserror work with domain-specific error types in Rust?

Yes, thiserror works with domain-specific error types in Rust by deriving Error on custom enums, allowing libraries to compose structured error hierarchies with clear, testable error messages.

What are the limitations of using anyhow for Rust library errors?

Using anyhow for Rust library errors limits typed error matching because it focuses on context-rich propagation rather exposing specific variants, making it less suitable for public APIs requiring structured error hierarchies.