Back to list
rileyhilliard

handling-errors

by rileyhilliard

62🍴 13📅 Jan 21, 2026

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

  1. Never swallow errors - Empty catch blocks hide bugs
  2. Never convert errors to booleans - Loses all context
  3. Preserve error context when wrapping or propagating
  4. 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

TypeExamplesHandling
ExpectedValidation, Not found, UnauthorizedReturn Result type, log info
TransientNetwork timeout, Rate limitRetry with backoff, log warn
UnexpectedNull reference, DB crashLog error, show support ID
CriticalAuth down, Payment gateway offlineCircuit 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

Anti-Patterns

PatternProblemFix
Empty catch blocksHides errorsLog or re-throw
return false on errorLoses contextReturn Result type
Generic "Error" messagesUndebuggableInclude what/why/context
Logging same error at each layerLog pollutionLog once at boundary
Bare except: / catch (e) allCatches system signalsCatch specific types

Score

Total Score

65/100

Based on repository quality metrics

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

Reviews

💬

Reviews coming soon