Error Handling
Errors are for humans and callers, not just the compiler.
Install 安装
curl -sSL https://updating.cc/skills/engineering-team/error-handling/SKILL.md -o ~/.agents/skills/engineering-team__error-handling/SKILL.mdSKILL.md Preview 技能内容预览
---
name: Error Handling
description: Errors are for humans and callers, not just the compiler.
---
# Error Handling
A good error carries enough context for the caller to react and for the operator to diagnose. "Something went wrong" satisfies the type checker and helps nobody.
## Principles
- **Handle or propagate, don't swallow.** An empty catch hides faults that surface far from their cause. If you truly must ignore, log why and swallow only that exact case.
- **Wrap with context.** As an error propagates up, add the layer's context: "fetching user 42" around "connection refused". The low-level message alone rarely tells you which user or why.
- **Distinguish error kinds.** Caller-recoverable (retry, fallback) vs caller-fatal (bug) vs expected (not found). Conflating them forces callers to treat everything as fatal.
- **Fail loud, early.** A wrong default silently applied is worse than a crash you'll notice.
## Logging
Log the structured facts (user_id, request_id, status), not a free-text essay. Humans grep; machines parse.