Rust error handling strategy: when to use Result, Option, panic, and which error crate.
Works with
Distinguishes between expected failures (Result/Option), bugs (panic), and unrecoverable errors; includes decision flowchart and core questions to ask before choosing a strategy
Recommends thiserror for typed library errors and anyhow for ergonomic application-level error handling; covers error propagation with ? and context attachment
Provides quick reference for unwrap vs expect vs panic, librar
AI-first code editor with Composer
Before installing skills in Cursor, ensure your development environment meets these requirements:
node --versionm06-error-handlingExecute the skills CLI command in your project's root directory to begin installation:
Fetches m06-error-handling from zhanghandong/rust-skills and configures it for Cursor.
The CLI shows a list of agents. Use arrow keys and space to select Cursor:
Confirm successful installation by checking the skill directory location:
Restart Cursor to activate m06-error-handling. Access via /m06-error-handling in your agent's command palette.
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Submit your Claude Code skill and start earning
Create detailed user stories, acceptance criteria, and feature specs
Example
Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios
Reduce spec writing time by 50%, ensure comprehensive coverage
Research competitors, compare features, identify gaps
Example
Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities
Complete competitive research in 2 hours instead of 2 days
Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs
Example
Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale
0
total installs
0
this week
979
GitHub stars
0
upvotes
Run in your terminal
0
installs
0
this week
979
stars
Layer 1: Language Mechanics
Is this failure expected or a bug?
Before choosing error handling strategy:
| Pattern | Don't Just Say | Ask Instead |
|---|---|---|
| unwrap panics | "Use ?" | Is None/Err actually possible here? |
| Type mismatch on ? | "Use anyhow" | Are error types designed correctly? |
| Lost error context | "Add .context()" | What does the caller need to know? |
| Too many error variants | "Use Box" | Is error granularity right? |
Before handling an error:
What kind of failure is this?
Who handles this?
What context is needed?
When error strategy is unclear:
"Should I return Result or Option?"
↑ Ask: Is absence/failure normal or exceptional?
↑ Check: m09-domain (what does domain say?)
↑ Check: domain-* (error handling requirements)
| Situation | Trace To | Question |
|---|---|---|
| Too many unwraps | m09-domain | Is the data model right? |
| Error context design | m13-domain-error | What recovery is needed? |
| Library vs app errors | m11-ecosystem | Who are the consumers? |
From design to implementation:
"Expected failure, library code"
↓ Use: thiserror for typed errors
"Expected failure, application code"
↓ Use: anyhow for ergonomic errors
"Absence is normal (find, get, lookup)"
↓ Use: Option<T>
"Bug or invariant violation"
↓ Use: panic!, assert!, unreachable!
"Need to propagate with context"
↓ Use: .context("what was happening")
| Pattern | When | Example |
|---|---|---|
Result<T, E> |
Recoverable error | fn read() -> Result<String, io::Error> |
Option<T> |
Absence is normal | fn find() -> Option<&Item> |
? |
Propagate error | let data = file.read()?; |
unwrap() |
Dev/test only | config.get("key").unwrap() |
expect() |
Invariant holds | env.get("HOME").expect("HOME set") |
panic! |
Unrecoverable | panic!("critical failure") |
| Context | Error Crate | Why |
|---|---|---|
| Library | thiserror |
Typed errors for consumers |
| Application | anyhow |
Ergonomic error handling |
| Mixed | Both | thiserror at boundaries, anyhow internally |
Is failure expected?
├─ Yes → Is absence the only "failure"?
│ ├─ Yes → Option<T>
│ └─ No → Result<T, E>
│ ├─ Library → thiserror
│ └─ Application → anyhow
└─ No → Is it a bug?
├─ Yes → panic!, assert!
└─ No → Consider if really unrecoverable
Use ? → Need context?
├─ Yes → .context("message")
└─ No → Plain ?
| Error | Cause | Fix |
|---|---|---|
unwrap() panic |
Unhandled None/Err | Use ? or match |
| Type mismatch | Different error types | Use anyhow or From |
| Lost context | ? without context |
Add .context() |
cannot use ? |
Missing Result return | Return Result<(), E> |
| Anti-Pattern | Why Bad | Better |
|---|---|---|
.unwrap() everywhere |
Panics in production | .expect("reason") or ? |
| Ignore errors silently | Bugs hidden | Handle or propagate |
panic! for expected errors |
Bad UX, no recovery | Result |
| Box everywhere | Lost type info | thiserror |
| When | See |
|---|---|
| Domain error strategy | m13-domain-error |
| Crate boundaries | m11-ecosystem |
| Type-safe errors | m05-type-driven |
| Mental models | m14-mental-model |
Make data-driven prioritization decisions faster
Draft PRDs, status updates, and stakeholder presentations
Example
Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement
Save 3-5 hours/week on communication overhead
Prerequisites
Time Estimate
30-60 minutes to see productivity improvements
Steps
Common Pitfalls
✓ Do
✗ Don't
💡 Pro Tips
✓ Use when
Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work.
✗ Avoid when
Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed.
mattpocock/skills
parcadei/continuous-claude-v3
cursor/plugins
ailabs-393/ai-labs-claude-skills
pproenca/dot-skills
mattpocock/skills
m06-error-handling is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
Registry listing for m06-error-handling matched our evaluation — installs cleanly and behaves as described in the markdown.
Solid pick for teams standardizing on skills: m06-error-handling is focused, and the summary matches what you get after install.
m06-error-handling reduced setup friction for our internal harness; good balance of opinion and flexibility.
m06-error-handling has been reliable in day-to-day use. Documentation quality is above average for community skills.
Keeps context tight: m06-error-handling is the kind of skill you can hand to a new teammate without a long onboarding doc.
m06-error-handling fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
m06-error-handling fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
m06-error-handling has been reliable in day-to-day use. Documentation quality is above average for community skills.
Useful defaults in m06-error-handling — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
showing 1-10 of 75