← スキル一覧に戻る

handling-errors
by rileyhilliard
⭐ 62🍴 13📅 2026年1月21日
SKILL.md
name: handling-errors description: Prevents silent failures and context loss in error handling. Use when writing try-catch blocks, designing error propagation, reviewing catch blocks, or implementing Result patterns.
Handling Errors
Iron Laws
- Never swallow errors - Empty catch blocks hide bugs
- Never convert errors to booleans - Loses all context
- Preserve error context when wrapping or propagating
- Log once where handled, not at every layer
Error Messages
Every error message answers: What happened? Why? How to recover?
For logs (developers):
logger.error("Failed to save user: Connection timeout after 30s", {
userId: user.id,
dbHost: config.db.host,
error: error.stack,
});
For users:
showError({
title: "Upload Failed",
message: "Your file is too large. Maximum size is 10MB.",
actions: [{ label: "Choose smaller file", onClick: selectFile }],
});
Error Categories
| Type | Examples | Handling |
|---|---|---|
| Expected | Validation, Not found, Unauthorized | Return Result type, log info |
| Transient | Network timeout, Rate limit | Retry with backoff, log warn |
| Unexpected | Null reference, DB crash | Log error, show support ID |
| Critical | Auth down, Payment gateway offline | Circuit breaker, alert |
Fail Fast vs Degrade Gracefully
Fail fast for critical dependencies:
await connectToDatabase(); // Throws on failure - app can't run without it
Degrade gracefully for optional features:
const prefs = await loadPreferences(userId).catch(() => DEFAULT_PREFS);
Log at the Right Layer
// ❌ Logging at every layer = same error 3x
async function fetchData() {
try { return await fetch(url); }
catch (e) { console.error("Fetch failed:", e); throw e; }
}
// ✅ Log once where handled
async function fetchData() {
const response = await fetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response;
}
// Top level logs the error once
Language-Specific Patterns
- TypeScript/React: See reference/typescript-react.md for Error Boundaries, typed errors, Result pattern, UI display
- Python: See reference/python.md for EAFP, exception chaining, context managers
- Go: See reference/go.md for explicit error returns, wrapping with %w, sentinel errors
Anti-Patterns
| Pattern | Problem | Fix |
|---|---|---|
| Empty catch blocks | Hides errors | Log or re-throw |
return false on error | Loses context | Return Result type |
| Generic "Error" messages | Undebuggable | Include what/why/context |
| Logging same error at each layer | Log pollution | Log once at boundary |
Bare except: / catch (e) all | Catches system signals | Catch specific types |
スコア
総合スコア
65/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
✓フォーク
10回以上フォークされている
+5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です