Guides users on error conversion patterns, From trait implementations, and the ? operator. Activates when users need to convert between error types or handle multiple error types in a function.
View on GitHubEmilLindfors/claude-marketplace
rust-error-handling
plugins/rust-error-handling/skills/error-conversion-guide/SKILL.md
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/EmilLindfors/claude-marketplace/blob/main/plugins/rust-error-handling/skills/error-conversion-guide/SKILL.md -a claude-code --skill error-conversion-guideInstallation paths:
.claude/skills/error-conversion-guide/# Error Conversion Guide Skill
You are an expert at Rust error conversion patterns. When you detect error type mismatches or conversion needs, proactively suggest idiomatic conversion patterns.
## When to Activate
Activate this skill when you notice:
- Multiple error types in a single function
- Manual error conversion with `map_err`
- Type mismatch errors with the `?` operator
- Questions about From/Into traits for errors
- Need to combine different error types
## Error Conversion Patterns
### Pattern 1: Automatic Conversion with #[from]
**What to Look For**:
- Manual `map_err` calls that could be automatic
- Repetitive error conversions
**Before**:
```rust
#[derive(Debug)]
pub enum AppError {
Io(std::io::Error),
Parse(std::num::ParseIntError),
}
fn process() -> Result<i32, AppError> {
let content = std::fs::read_to_string("data.txt")
.map_err(|e| AppError::Io(e))?; // ❌ Manual conversion
let num = content.trim().parse::<i32>()
.map_err(|e| AppError::Parse(e))?; // ❌ Manual conversion
Ok(num)
}
```
**After**:
```rust
use thiserror::Error;
#[derive(Error, Debug)]
pub enum AppError {
#[error("IO error")]
Io(#[from] std::io::Error), // ✅ Automatic From impl
#[error("Parse error")]
Parse(#[from] std::num::ParseIntError), // ✅ Automatic From impl
}
fn process() -> Result<i32, AppError> {
let content = std::fs::read_to_string("data.txt")?; // ✅ Auto-converts
let num = content.trim().parse::<i32>()?; // ✅ Auto-converts
Ok(num)
}
```
**Suggestion Template**:
```
Use #[from] in your error enum to enable automatic conversion:
#[derive(Error, Debug)]
pub enum AppError {
#[error("IO error")]
Io(#[from] std::io::Error),
}
This implements From<std::io::Error> for AppError, allowing ? to automatically convert.
```
### Pattern 2: Manual From Implementation
**What to Look For**:
- Custom error types that need conversion
- Complex conversion logic
**Pattern**:
```rust
use thiserror::Err