← ClaudeAtlas

error-handling-patternslisted

Error handling best practices - cause chaining, boundary validation, structured errors, fire-and-forget safety, retry discipline
kookr-ai/kookr · ★ 2 · AI & Automation · score 71
Install: claude install-skill kookr-ai/kookr
# Error Handling Patterns Rules for writing code that fails safely, predictably, and visibly. **Research:** `docs/deepresearch/reports/AI Coding Agent Error Handling Guidelines.md`, `docs/deepresearch/reports/Git Commit Discipline for AI Coding Agents.md` ## Non-Negotiable Rules These rules are ALWAYS enforced when writing or reviewing code: | # | Rule | Violation Example | Correct Pattern | |---|------|-------------------|-----------------| | 1 | **No empty catch blocks** | `catch { }` | `catch (err) { logger.debug({ err }, 'context'); }` | | 2 | **Always chain cause** | `throw new Error(msg)` in catch | `throw new Error(msg, { cause: err })` | | 3 | **No fire-and-forget** | `void asyncFn()` | `asyncFn().catch(err => logger.error({ err }))` | | 4 | **Validate at boundary** | `body as MyType` | `MySchema.safeParse(body)` | | 5 | **Parameterized SQL** | `` `WHERE x = '${val}'` `` | `` sql`WHERE x = ${val}` `` | | 6 | **Structured logging** | `console.log(error)` | `logger.error({ err }, 'context')` | | 7 | **Bound concurrency** | `Promise.all(big.map(fn))` | `Promise.all(big.map(x => limit(() => fn(x))))` | | 8 | **Never throw strings** | `throw "failed"` | `throw new Error("failed")` | | 9 | **Idempotency keys for retried mutations** | Retry `POST /pay` without key | Add `Idempotency-Key` header | | 10 | **Top-level error boundary** | Unhandled error crashes server | Global error middleware catches all | ## Error Classification | Type | Examples | Response | Retry? | |