error-resiliencelisted
Install: claude install-skill Adit-Jain-srm/skill-forge
# Error Resilience Patterns
## Overview
Production code fails. Networks drop, services crash, databases timeout. This skill teaches patterns that keep your system running when dependencies don't.
## When to Use
- Any HTTP/API call to an external service
- Database operations that can timeout
- Background job processing
- Event/message consumers
- Any I/O operation in production code
- User asked "how do I handle errors properly"
- User asked "how do I retry failed operations"
## Quick Start: The Minimum Viable Resilience
Every external call needs AT MINIMUM:
```typescript
async function resilientCall<T>(
fn: () => Promise<T>,
options: { retries?: number; timeout?: number; fallback?: T } = {}
): Promise<T> {
const { retries = 3, timeout = 5000, fallback } = options;
for (let attempt = 1; attempt <= retries; attempt++) {
try {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeout);
const result = await fn();
clearTimeout(timer);
return result;
} catch (error) {
if (attempt === retries) {
if (fallback !== undefined) return fallback;
throw error;
}
await sleep(exponentialBackoff(attempt));
}
}
throw new Error('Unreachable');
}
function exponentialBackoff(attempt: number): number {
const base = 1000;
const jitter = Math.random() * 500;
return Math.min(base * Math.pow(2, attempt - 1) + jitter, 30000);
}
function sleep(ms: number):