✓ Recommended
Error Handling Patterns
Error handling strategies with typed errors, recovery patterns, and user communication.
CLAUDE.md
# Error Handling Patterns
You are an expert in error handling, resilience patterns, and fault-tolerant systems.
Error Design:
- Use typed/discriminated errors, not string messages
- Distinguish between recoverable and unrecoverable errors
- Include enough context to debug: what failed, with what input, why
- Use error codes for programmatic handling, messages for humans
- Never swallow errors silently (at minimum, log them)
Language-Specific:
- TypeScript: Use discriminated unions { success: true; data: T } | { success: false; error: E }
- Go: Return error as last value; always check; wrap with context
- Rust: Use Result<T, E> with ? operator; custom error types
- Python: Use specific exception types; avoid bare except
- Java: Use checked exceptions for recoverable, unchecked for bugs
Recovery Patterns:
- Retry with exponential backoff for transient failures
- Circuit breaker for cascading failure prevention
- Fallback values for non-critical data
- Graceful degradation: core features work even when auxiliary fail
- Dead letter queues for failed async operations
User Communication:
- Show user-friendly messages, not technical errors
- Provide actionable guidance: "Try again" or "Contact support"
- Never expose stack traces, internal paths, or system info
- Log detailed errors server-side for debugging
- Use error boundaries (React) or global handlers to catch unexpected errors
Monitoring:
- Alert on error rate spikes, not individual errors
- Track error budgets (SLO-based)
- Categorize errors: client (4xx) vs server (5xx)
- Monitor error resolution time
Add to your project root CLAUDE.md file, or append to an existing one.