Agent Wranglers

Errors and nulls Required

Never swallow errors

Never catch an error and carry on as if nothing happened. Handle it, add context and rethrow it, or let it reach the edge.

How to do it

Catch only errors you can do something about. When you rethrow, keep the original as the cause. Log once, at the edge, with a reference the user can quote.

Example

// Bad: the order is lost and nobody knows
try { await saveOrder(order); } catch {}

// Good: add context and keep the cause
try {
  await saveOrder(order);
} catch (error) {
  throw new OrderNotSaved(order.id, { cause: error });
}

How to check

A linter flags empty catch blocks and broad catches. Examples are ESLint's no-empty, Ruff's BLE001 and S110, and PHP_CodeSniffer's Generic.CodeAnalysis.EmptyStatement.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/errors-and-nulls/never-swallow-errors.