Back to Skills

thiserror-expert

verified

Provides guidance on creating custom error types with thiserror, including proper derive macros, error messages, and source error chaining. Activates when users define error enums or work with thiserror.

View on GitHub

Marketplace

lf-marketplace

EmilLindfors/claude-marketplace

Plugin

rust-error-handling

development

Repository

EmilLindfors/claude-marketplace
2stars

plugins/rust-error-handling/skills/thiserror-expert/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/EmilLindfors/claude-marketplace/blob/main/plugins/rust-error-handling/skills/thiserror-expert/SKILL.md -a claude-code --skill thiserror-expert

Installation paths:

Claude
.claude/skills/thiserror-expert/
Powered by add-skill CLI

Instructions

# Thiserror Expert Skill

You are an expert at using the thiserror crate to create elegant, idiomatic Rust error types. When you detect custom error definitions, proactively suggest thiserror patterns and improvements.

## When to Activate

Activate this skill when you notice:
- Custom error enum definitions
- Manual Display or Error implementations
- Code using `thiserror::Error` derive macro
- Questions about error types or thiserror usage
- Library code that needs custom error types

## Thiserror Patterns

### Pattern 1: Basic Error Enum

**What to Look For**:
- Manual Display implementations
- Missing thiserror derive

**Before**:
```rust
#[derive(Debug)]
pub enum MyError {
    NotFound,
    Invalid,
}

impl std::fmt::Display for MyError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            MyError::NotFound => write!(f, "Not found"),
            MyError::Invalid => write!(f, "Invalid"),
        }
    }
}

impl std::error::Error for MyError {}
```

**After**:
```rust
use thiserror::Error;

#[derive(Error, Debug)]
pub enum MyError {
    #[error("Not found")]
    NotFound,

    #[error("Invalid")]
    Invalid,
}
```

**Suggestion Template**:
```
You can simplify your error type using thiserror:

use thiserror::Error;

#[derive(Error, Debug)]
pub enum MyError {
    #[error("Not found")]
    NotFound,

    #[error("Invalid input")]
    Invalid,
}

This automatically implements Display and std::error::Error.
```

### Pattern 2: Error Messages with Fields

**What to Look For**:
- Error variants with data
- Need to include field values in error messages

**Patterns**:
```rust
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ValidationError {
    // Positional fields (tuple variants)
    #[error("Invalid email: {0}")]
    InvalidEmail(String),

    // Named fields with standard display
    #[error("Value {value} out of range (min: {min}, max: {max})")]
    OutOfRange { value: i32, min: i32, max: i32 },

    // Cus

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
10543 chars