Review error handling
Find the swallowed exceptions and the errors that cannot be diagnosed
Review the error handling in the code below. Focus only on the failure paths: 1) which exceptions are swallowed or downgraded to a default value — will a failure pass silently? 2) is the error message enough to locate the cause (does it carry the key id, the inputs, the upstream state)? 3) which retries are unsafe (non-idempotent, double-charging or double-writing)? 4) where should it fail but keeps running, and where should it keep going but aborts entirely? 5) give the corrected key snippets. ``` [paste your code] ```
How to use
Look first at the silent failures it flags. Those are the hardest bugs to find after release, and the hardest to trace back.
Good for
- Production shows 'no error, wrong data' and the logs are empty.
- You are wiring up payments, refunds or a message queue, where the failure path costs far more than the happy path.
Not for
- It is a one-off script or CLI: swallowing an exception to keep going is a reasonable choice, so do not review it like a service.
- The problem is the retry design as a whole (queue, dead letters, backoff), not a single try/catch: look at the architecture.
Example
Input
def charge(order_id, amount):
try:
resp = payment.charge(order_id, amount)
db.update(order_id, status="paid")
return True
except Exception:
return FalseWhat you get
Point out that `except Exception` swallows everything with no log, so the cause cannot be diagnosed; that a successful payment followed by a failed db.update double-charges, since there is no idempotency key and no transaction boundary; and that returning a bool hides the difference between 'insufficient funds' and 'network timeout'. Fix: log order_id, amount and the upstream error code, add an idempotency key, and write local state before confirming.
Common mistakes
- Asking only to 'add some logging' without separating 'should fail' from 'should retry': the logs improve and the semantics stay wrong.
- The code you paste has already flattened the exception with `str(e)`, so it cannot see the error type and falls back to generic advice.
Try tweaking it like this
- Add 'rank fixes by whether the user loses money, sees an error, or just loses a stat' and the output maps straight to a schedule.
- Ask for 'the user-facing message for each failure' to force out the concrete silent-failure cases.