# Rs Error Excellence

> Idiomatic patterns for robust, transparent, and recoverable error handling in Rust.

- Skill: `jcorpac/rs-error-excellence` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jcorpac/rs-error-excellence`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jcorpac/rs-error-excellence/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jcorpac (https://skillmd.com/u/jcorpac)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/jcorpac/rs-error-excellence

---


# Rust Error Excellence

Rust treats errors as values, not exceptions. This skill ensures your errors provide maximum context for developers and users.

## The `Result<T, E>` Pattern
Always return `Result` for functions that can fail. Use the `?` operator to propagate errors up the stack.

## Crate Selection
- **`anyhow`**: Best for **applications**. It provides a flexible, easy-to-use error type for top-level handling.
- **`thiserror`**: Best for **libraries**. It allows you to define custom, derive-based error enums that users can match against.

## Best Practices
- **Context**: Use `.with_context(|| ...)` in Anyhow to add human-readable breadcrumbs to errors.
- **Avoid Panics**: Use `unwrap()` and `expect()` ONLY in tests or when you can prove an invariant is impossible to break.
- **Custom Errors**: Define domain-specific error enums for complex logic.


