huiali/rust-skills/rust-error
Claude Code and agent skill by huiali/rust-skills
- community
Checking that the SKILL.md file is still in the repository.
Error handling expert covering Result, Option, panic strategies, custom error types with thiserror/anyhow, error propagation patterns, and context-rich error chains.
Install
npx vskill@latest install huiali/rust-skills/rust-errorSKILL.md
Solution Patterns
Pattern 1: Option for Normal Absence
When to use: Queries, lookups, optional configuration values.
Key insight: None carries no information, just absence.
Pattern 2: Result for Expected Failures
When to use: I/O operations, parsing, validation, network calls.
Key insight: Error type carries information about why it failed.
Pattern 3: Custom Error Types (thiserror)
When to use: Library code, public APIs, need type-safe error handling.
Trade-offs: More boilerplate, but precise error types.
Pattern 4: Flexible Errors (anyhow)
When to use: Application code, rapid development, error context matters more than types.
Trade-offs: Loses type information, but gains flexibility and context.
Workflow
Step 1: Classify the Failure
Step 2: Choose Error Representation
Step 3: Propagate or Handle
Error Propagation Best Practices
✅ Good Patterns
❌ Anti-Patterns
When to Panic
✅ Acceptable Panic Scenarios
| Scenario | Example | Reasoning | |
|---|---|---|---|
| Invariant violation | Array index out of bounds | Programming bug | |
| Initialization checks | env::var("HOME").expect(...) | Required for program to run | |
| Test assertions | assert_eq!(result, expected) | Verify assumptions | |
| Unrecoverable state | OOM, corrupted data structures | Can't continue safely |
❌ Unacceptable Panic Scenarios
Error Type Design
Enum for Multiple Error Cases
Nested Errors with Context
Common Pitfalls
| Anti-Pattern | Problem | Correct Approach | |
|---|---|---|---|
.unwrap() everywhere | Production panics | Use ? or .with_context() | |
Box<dyn Error> | Loses type information | Use thiserror enums | |
| Silent error ignoring | Bugs go unnoticed | Handle or propagate | |
| Deep error hierarchies | Over-engineering | Design as needed | |
| Panic for control flow | Abusing panic | Use normal control flow | |
| String errors | No pattern matching | Use typed errors |
Quick Reference
| Scenario | Choice | Tool | |
|---|---|---|---|
| Library returns custom errors | Result<T, CustomEnum> | thiserror | |
| Application rapid development | Result<T, anyhow::Error> | anyhow | |
| Absence is normal | Option<T> | None / Some(x) | |
| Intentional panic | panic!() / assert!() | Special cases only | |
| Error conversion | .map_err() / .context() | Add context | |
| Fallback values | .unwrap_or() / .unwrap_or_else() | Safe defaults | |
| Early return | ? operator | Propagate errors |
Review Checklist
When reviewing error handling code:
- [ ] All fallible operations return
ResultorOption - [ ] Error types are meaningful (not just
String) - [ ] Error context is preserved through propagation
- [ ]
unwrap()used only with justification (comments) - [ ]
panic!()used only for bugs or unrecoverable states - [ ] Library code uses typed errors (thiserror)
- [ ] Application code adds context (anyhow
.context()) - [ ] Error messages are actionable for users/operators
- [ ] No silent error swallowing (
let _ = ...) - [ ] Tests cover error paths, not just happy paths
Verification Commands
Conversion Patterns
Option ↔ Result
Error Type Conversions
Advanced: Error Source Chains
Related Skills
- rust-error-advanced - Advanced error patterns (thiserror, anyhow, error chains)
- rust-anti-pattern - Error handling anti-patterns to avoid
- rust-coding - Error handling coding standards
- rust-web - Error handling in web contexts
- rust-async - Error handling in async code
Localized Reference
- Chinese version: SKILL_ZH.md - 完整中文版本,包含所有内容
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/rust-error/SKILL.md
Popularity
- Repository stars
- 29
- Repository forks
- 4
- 7-day trend score
- 17
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 9 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/huiali/rust-skills/rust-error)