โ† Back to list
rustfs

m06-error-handling

by rustfs

๐Ÿš€2.3x faster than MinIO for 4KB object payloads. RustFS is an open-source, S3-compatible high-performance object storage system supporting migration and coexistence with other S3-compatible platforms such as MinIO and Ceph.

โญ 20,125๐Ÿด 866๐Ÿ“… Jan 23, 2026

SKILL.md


name: m06-error-handling description: "CRITICAL: Use for error handling. Triggers: Result, Option, Error, ?, unwrap, expect, panic, anyhow, thiserror, when to panic vs return Result, custom error, error propagation, ้”™่ฏฏๅค„็†, Result ็”จๆณ•, ไป€ไนˆๆ—ถๅ€™็”จ panic"

Error Handling

Layer 1: Language Mechanics

Core Question

Is this failure expected or a bug?

Before choosing error handling strategy:

  • Can this fail in normal operation?
  • Who should handle this failure?
  • What context does the caller need?

Error โ†’ Design Question

PatternDon't Just SayAsk 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?

Thinking Prompt

Before handling an error:

  1. What kind of failure is this?

    • Expected โ†’ Result<T, E>
    • Absence normal โ†’ Option
    • Bug/invariant โ†’ panic!
    • Unrecoverable โ†’ panic!
  2. Who handles this?

    • Caller โ†’ propagate with ?
    • Current function โ†’ match/if-let
    • User โ†’ friendly error message
    • Programmer โ†’ panic with message
  3. What context is needed?

    • Type of error โ†’ thiserror variants
    • Call chain โ†’ anyhow::Context
    • Debug info โ†’ anyhow or tracing

Trace Up โ†‘

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)
SituationTrace ToQuestion
Too many unwrapsm09-domainIs the data model right?
Error context designm13-domain-errorWhat recovery is needed?
Library vs app errorsm11-ecosystemWho are the consumers?

Trace Down โ†“

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")

Quick Reference

PatternWhenExample
Result<T, E>Recoverable errorfn read() -> Result<String, io::Error>
Option<T>Absence is normalfn find() -> Option<&Item>
?Propagate errorlet data = file.read()?;
unwrap()Dev/test onlyconfig.get("key").unwrap()
expect()Invariant holdsenv.get("HOME").expect("HOME set")
panic!Unrecoverablepanic!("critical failure")

Library vs Application

ContextError CrateWhy
LibrarythiserrorTyped errors for consumers
ApplicationanyhowErgonomic error handling
MixedBoththiserror at boundaries, anyhow internally

Decision Flowchart

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 ?

Common Errors

ErrorCauseFix
unwrap() panicUnhandled None/ErrUse ? or match
Type mismatchDifferent error typesUse anyhow or From
Lost context? without contextAdd .context()
cannot use ?Missing Result returnReturn Result<(), E>

Anti-Patterns

Anti-PatternWhy BadBetter
.unwrap() everywherePanics in production.expect("reason") or ?
Ignore errors silentlyBugs hiddenHandle or propagate
panic! for expected errorsBad UX, no recoveryResult
Box everywhereLost type infothiserror

WhenSee
Domain error strategym13-domain-error
Crate boundariesm11-ecosystem
Type-safe errorsm05-type-driven
Mental modelsm14-mental-model

Score

Total Score

90/100

Based on repository quality metrics

โœ“SKILL.md

SKILL.mdใƒ•ใ‚กใ‚คใƒซใŒๅซใพใ‚Œใฆใ„ใ‚‹

+20
โœ“LICENSE

ใƒฉใ‚คใ‚ปใƒณใ‚นใŒ่จญๅฎšใ•ใ‚Œใฆใ„ใ‚‹

+10
โœ“่ชฌๆ˜Žๆ–‡

100ๆ–‡ๅญ—ไปฅไธŠใฎ่ชฌๆ˜ŽใŒใ‚ใ‚‹

+10
โœ“ไบบๆฐ—

GitHub Stars 1000ไปฅไธŠ

+15
โœ“ๆœ€่ฟ‘ใฎๆดปๅ‹•

1ใƒถๆœˆไปฅๅ†…ใซๆ›ดๆ–ฐ

+10
โœ“ใƒ•ใ‚ฉใƒผใ‚ฏ

10ๅ›žไปฅไธŠใƒ•ใ‚ฉใƒผใ‚ฏใ•ใ‚Œใฆใ„ใ‚‹

+5
โ—‹Issue็ฎก็†

ใ‚ชใƒผใƒ—ใƒณIssueใŒ50ๆœชๆบ€

0/5
โœ“่จ€่ชž

ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐ่จ€่ชžใŒ่จญๅฎšใ•ใ‚Œใฆใ„ใ‚‹

+5
โœ“ใ‚ฟใ‚ฐ

1ใคไปฅไธŠใฎใ‚ฟใ‚ฐใŒ่จญๅฎšใ•ใ‚Œใฆใ„ใ‚‹

+5

Reviews

๐Ÿ’ฌ

Reviews coming soon