thiserror-expertlisted
Install: claude install-skill aiskillstore/marketplace
# 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: