Review Error Handling
Purpose
Find where failures are lost, misclassified, retried unsafely or shown badly, and give concrete fixes so the code fails predictably, recovers where it can and tells operators and users the right thing.
When to use
- Incidents showed silent failures, duplicate side effects or misleading error messages.
- Code calls external systems (HTTP, queues, databases, files) and is about to go to production.
- A reviewer wants a focused look at exceptions, retries and fallbacks.
When not to use
- System-level resilience (bulkheads, failover, capacity). Use
resilience-review.
- Wording of user-facing messages only. Use
error-message-writing.
- A general pull request review. Use
code-review.
Inputs
Required:
- The code (and its language) whose error handling is reviewed.
Optional, improves quality:
- Called services' error contracts and idempotency guarantees, SLOs/timeouts, team error-handling conventions, recent incidents.
If the external contract is unknown, state which findings depend on it and mark them [UNKNOWN].
Process
- List failure points: every external call, parse, conversion, lock, resource acquisition and invariant check.
- For each, classify errors: expected business outcome (e.g. insufficient funds) vs transient technical (timeout, 503) vs permanent technical (400, schema mismatch) vs programming bug.
- Check detection: timeouts set on every remote call; status codes and response bodies checked; partial responses handled.
- Check propagation: no empty or log-and-continue catches; no catching the base exception type except at boundaries; cause/context preserved when wrapping; business outcomes modeled as results or domain errors, not generic exceptions.
- Check retries: only transient errors; bounded attempts with exponential backoff and jitter; total time within caller's timeout; the operation is idempotent (idempotency key) or retries are unsafe.
- Check consistency: side effects across a failure (DB updated but call failed, or vice versa); transactions and compensations; outbox for "update and notify".
- Check cleanup: resources released on all paths (finally/using/defer/with); locks released; no half-written files.
- Check fallbacks and circuit breaking: fallback is correct for the business, not just "return empty"; degraded mode is visible.
- Check reporting: one log entry per error at the right boundary with correlation id and no secrets or personal data; user-facing messages are actionable and leak no internals; API errors use a stable code.
- Prioritize findings (Critical: data loss/duplicate money movement; High: silent failure; Medium: poor diagnosis; Low: style) and give code-level fixes.
- If the goal continues, suggest
logging-instrumentation for diagnosability gaps, resilience-review for system-level failure modes or error-message-writing for user-facing texts.
Output format
# Error Handling Review: <unit>
## Failure Point Inventory
| # | Operation | Error classes | Current handling |
## Findings
| # | Severity | Location | Problem | Consequence | Fix |
## Recommended Pattern
<short code sketch for the main fix>
## Open Questions
Quality checklist
Common pitfalls
- Retrying non-idempotent calls (payments, emails) and causing duplicates. Require an idempotency key or do not retry.
- Logging and rethrowing at every layer, producing five stack traces for one error. Log once at the boundary.
- Treating business outcomes as exceptions and technical failures as normal results, which confuses callers and metrics.
Example
Input: "PaymentClient: call provider, catch Exception, retry 5 times, then set order to FAILED."
Excerpt of output:
| # |
Severity |
Location |
Problem |
Consequence |
Fix |
| 1 |
Critical |
charge() retry loop |
Retries on read timeout without idempotency key |
Customer may be charged twice |
Send Idempotency-Key = orderId; retry only connect errors/503 |
| 2 |
High |
catch (Exception) |
Card declined treated like a technical error |
Order marked FAILED and retried |
Map declines to PaymentDeclined result; no retry |
1---2name: error-handling-review3description: "Reviews how code detects, propagates, retries, falls back from and reports errors: exception design, swallowed or over-broad catches, retry and timeout policy, idempotency, resource cleanup, transactional consistency and user-facing error messages. Use when failures are silent or confusing, before hardening a service or integration, or when someone asks to review error handling, exceptions or resilience of code."4license: MIT5metadata:6 source: https://skillmd.com/skills/muratdincer/error-handling-review7 version: "1.0.0"8 language: en9 category: 05-engineering10 role: developer11 area: coding12 title: "Review error handling"13 related: "resilience-review, logging-instrumentation, error-message-writing, code-review, error-scenario-catalog"14 prompt: "Review the error handling in this payment client: it calls the provider over HTTP, retries on failure and updates the order status."15---1617# Review Error Handling1819## Purpose20Find where failures are lost, misclassified, retried unsafely or shown badly, and give concrete fixes so the code fails predictably, recovers where it can and tells operators and users the right thing.2122## When to use23- Incidents showed silent failures, duplicate side effects or misleading error messages.24- Code calls external systems (HTTP, queues, databases, files) and is about to go to production.25- A reviewer wants a focused look at exceptions, retries and fallbacks.2627## When not to use28- System-level resilience (bulkheads, failover, capacity). Use `resilience-review`.29- Wording of user-facing messages only. Use `error-message-writing`.30- A general pull request review. Use `code-review`.3132## Inputs33Required:34- The code (and its language) whose error handling is reviewed.3536Optional, improves quality:37- Called services' error contracts and idempotency guarantees, SLOs/timeouts, team error-handling conventions, recent incidents.3839If the external contract is unknown, state which findings depend on it and mark them `[UNKNOWN]`.4041## Process421. List failure points: every external call, parse, conversion, lock, resource acquisition and invariant check.432. For each, classify errors: expected business outcome (e.g. insufficient funds) vs transient technical (timeout, 503) vs permanent technical (400, schema mismatch) vs programming bug.443. Check detection: timeouts set on every remote call; status codes and response bodies checked; partial responses handled.454. Check propagation: no empty or log-and-continue catches; no catching the base exception type except at boundaries; cause/context preserved when wrapping; business outcomes modeled as results or domain errors, not generic exceptions.465. Check retries: only transient errors; bounded attempts with exponential backoff and jitter; total time within caller's timeout; the operation is idempotent (idempotency key) or retries are unsafe.476. Check consistency: side effects across a failure (DB updated but call failed, or vice versa); transactions and compensations; outbox for "update and notify".487. Check cleanup: resources released on all paths (finally/using/defer/with); locks released; no half-written files.498. Check fallbacks and circuit breaking: fallback is correct for the business, not just "return empty"; degraded mode is visible.509. Check reporting: one log entry per error at the right boundary with correlation id and no secrets or personal data; user-facing messages are actionable and leak no internals; API errors use a stable code.5110. Prioritize findings (Critical: data loss/duplicate money movement; High: silent failure; Medium: poor diagnosis; Low: style) and give code-level fixes.5211. If the goal continues, suggest `logging-instrumentation` for diagnosability gaps, `resilience-review` for system-level failure modes or `error-message-writing` for user-facing texts.5354## Output format55```markdown56# Error Handling Review: <unit>57## Failure Point Inventory58| # | Operation | Error classes | Current handling |5960## Findings61| # | Severity | Location | Problem | Consequence | Fix |6263## Recommended Pattern64<short code sketch for the main fix>6566## Open Questions67```6869## Quality checklist70- [ ] Every remote call has a timeout and a classified error path.71- [ ] Retries are limited to transient errors and to idempotent operations.72- [ ] No finding recommends catching everything without a boundary reason.73- [ ] Consistency across failures (DB vs external side effect) is analyzed.74- [ ] Logging advice avoids duplicates, secrets and personal data.75- [ ] Inferences are labeled `[ASSUMPTION]` and listed as assumptions or open questions; nothing unsupported is stated as fact.76- [ ] All checks pass; if any fails, revise the output and re-run this checklist before answering.7778## Common pitfalls79- Retrying non-idempotent calls (payments, emails) and causing duplicates. Require an idempotency key or do not retry.80- Logging and rethrowing at every layer, producing five stack traces for one error. Log once at the boundary.81- Treating business outcomes as exceptions and technical failures as normal results, which confuses callers and metrics.8283## Example84Input: "PaymentClient: call provider, catch Exception, retry 5 times, then set order to FAILED."8586Excerpt of output:87| # | Severity | Location | Problem | Consequence | Fix |88|---|---|---|---|---|---|89| 1 | Critical | `charge()` retry loop | Retries on read timeout without idempotency key | Customer may be charged twice | Send `Idempotency-Key = orderId`; retry only connect errors/503 |90| 2 | High | `catch (Exception)` | Card declined treated like a technical error | Order marked FAILED and retried | Map declines to `PaymentDeclined` result; no retry |