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 GitHubEmilLindfors/claude-marketplace
rust-error-handling
January 20, 2026
Select agents to install to:
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-expertInstallation paths:
.claude/skills/thiserror-expert/# 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