Errors that hide bugs: swallowed exceptions, shared state and false success
Some of the worst bugs report success. Look for the places where errors disappear and state goes wrong.
Remember: For every catch, ask who learns about the failure and what the caller receives. For every module-level value, ask who else can see it.
A review is not only about attackers. Ignored errors, half-finished writes and state shared between requests cause the same damage as an attack: money moved twice, money lost, or one user's data shown to another.
Patterns to look for
- Empty catch blocks, bare except, catch (e) {} and runCatching that returns a default value.
- Promises started in a loop or in forEach and never awaited.
- A success response returned before the work finishes, or after part of it failed.
- Default arguments, module-level variables and caches that are shared between requests.
- Multi-step writes without a transaction: debit, crash, and no credit.
- Retries without idempotency keys, so the same operation runs twice.
- Error messages and stack traces returned to the client.
def process_payments(payments, ledger=[]):
for p in payments:
try:
ledger.append(charge(p["account"], p["amount"]))
except:
pass
invoices.forEach(async (inv) => {
await bank.transfer(inv.iban, inv.amountMinor);
});
return { status: "ok" };
Test failures on purpose: make the third of ten operations fail, and check the state afterwards. The question is not whether the code works when everything goes right, but what state is left when something goes wrong.
Questions to ask yourself
- What happens if this step fails halfway through?
- Who is told about the failure, and what does the caller receive?
- Is any state shared between requests?
Practise this
- Batch payments with a shared default list · Business logic
- Paying invoices with forEach and an async callback · Business logic