thiserror-expert

Guide Rust error type design using thiserror derive macros and patterns.

2|1|Updated Oct 31, 2025
One-click install
npx skills add https://github.com/EmilLindfors/claude-marketplace --skill thiserror-expert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: thiserror-expert
Source: https://github.com/EmilLindfors/claude-marketplace/tree/main/plugins/rust-error-handling/skills/thiserror-expert
Command: npx skills add https://github.com/EmilLindfors/claude-marketplace --skill thiserror-expert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides guidance on creating custom error types with thiserror, including derive macros, error messages, and source error chaining.

Core Features & Use Cases

  • Pattern 1: Basic Error Enum: Replace manual Display/Error implementations with #[derive(Error)].
  • Pattern 2: Error Messages with Fields: Rich error messages using named or positional fields.
  • Pattern 3: Wrapping Source Errors with #[from]: Automatic From implementations for seamless error propagation.
  • Additional guidance on error context, chaining, and readability.

Quick Start

Define a simple error enum with #[derive(Error)] and use #[from] wrappers for io::Error.

Frequently Asked Questions about thiserror-expert

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

FAQPage Schema
How do I create custom error types in Rust with thiserror?

Custom error types in Rust use the thiserror crate's #[derive(Error)] macro to automatically implement Display and std::error::Error traits. Define an enum with variants, annotate fields with #[error("...")], and thiserror generates the boilerplate for you, reducing manual implementation.

What's the best way to wrap and propagate source errors in Rust?

Use thiserror's #[from] attribute on error enum variants to automatically implement From trait implementations. This enables seamless error propagation—wrap io::Error, parse errors, or other sources directly, and thiserror chains them while preserving context for debugging.

How do I add rich error messages with fields to my Rust error enum?

Define error variants with named or positional fields, then use #[error("message with {field}")] to include dynamic data. thiserror's derive macro formats these fields into Display output, making error messages informative without manual Display trait coding.

Can I use thiserror to automatically implement error chaining and source tracking?

Yes. Combine #[from] for automatic From implementations with #[source] to mark the underlying error. thiserror generates source() method implementations that let users traverse the error chain and understand root causes, improving debuggability.

When should I use thiserror instead of manually implementing Display and Error?

Use thiserror for any custom error enum to eliminate repetitive boilerplate. It's ideal when you need transparent error forwarding, source chaining, or rich contextual messages—thiserror handles trait implementations so you focus on error semantics and readability.