principleModeratepending
Principle: Fail fast, recover gracefully
Viewed 0 times
fail fastgraceful degradationerror handlingresiliencecircuit breaker
Problem
Systems that silently swallow errors or continue in degraded states produce hard-to-debug issues and data corruption.
Solution
Fail fast during development, recover gracefully in production:
Fail Fast (catch bugs early):
Recover Gracefully (handle expected failures):
Where to draw the line:
The worst pattern: catching all exceptions silently.
It hides bugs, produces wrong results, and makes debugging impossible.
Fail Fast (catch bugs early):
- Validate inputs at function boundaries
- Use assertions for programmer errors (not user errors)
- Crash on impossible states rather than 'handling' them
- Strict mode, strict compiler flags, strict linting
- Return errors, don't swallow them
// BAD: Silent failure
function getUser(id) {
try {
return db.query(id);
} catch {
return null; // Caller has no idea something went wrong
}
}
// GOOD: Fail fast
function getUser(id) {
if (!id) throw new Error('getUser requires an id');
return db.query(id); // Let errors propagate
}Recover Gracefully (handle expected failures):
- Retry with backoff for transient errors (network, rate limits)
- Circuit breakers for failing dependencies
- Fallback values for non-critical features
- Graceful degradation (show cached data if API is down)
- Clear error messages for users
Where to draw the line:
- Programming errors (wrong type, impossible state): CRASH
- Infrastructure errors (network, disk): RETRY then FAIL
- User errors (bad input, permissions): REPORT clearly
- External service errors: DEGRADE gracefully
The worst pattern: catching all exceptions silently.
It hides bugs, produces wrong results, and makes debugging impossible.
Why
Silent failures create distance between the bug and its symptoms. Failing fast keeps cause and effect close together, making bugs easy to find.
Context
Error handling strategy for applications
Revisions (0)
No revisions yet.