handling-errors

star 122

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.

rileyhilliard By rileyhilliard schedule Updated 5/10/2026

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

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

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
Install via CLI
npx skills add https://github.com/rileyhilliard/claude-essentials --skill handling-errors
Repository Details
star Stars 122
call_split Forks 19
navigation Branch main
article Path SKILL.md
More from Creator
rileyhilliard
rileyhilliard Explore all skills →