Skip to content

The error handling recipes are copy-paste prompts for Claude Code, Codex, and Cursor that cover four jobs around a production failure: debugging, logging, recovery, and monitoring. Every recipe follows one rule: the agent attaches evidence that a check failed before the change and passes after it, so you approve evidence instead of reading every line.

This hub is for developers who hand production errors to an agent, and for tech leads who approve those fixes. You know the situation: the API returns 500s, the logs say Error: undefined, and the agent’s first fix wraps the call in try/catch so the error disappears from the dashboard but not from your users’ screens.

Which error handling recipe fits your problem?

Section titled “Which error handling recipe fits your problem?”

Start from the symptom. The last column is the evidence the agent attaches to the pull request.

Your problemRecipeThe check that proves it
A bug you can see but cannot explain: a stack trace, an intermittent failure, a leak, a raceDebugging patternsA reproduction that fails on the unfixed code and passes after the fix
Logs that are console.log strings, lack request IDs, or leak secretsLogging patternsA test that asserts the structured fields and that a secret never reaches the output
A flaky dependency that takes your service down with itRecovery patternsA chaos or fault-injection test that kills the dependency and checks the fallback
Errors your users find before you do: no alerts, noisy alerts, no SLOMonitoring and logging patternspromtool test rules and a query that returns real data

Starting from nothing? Fix the logs first, because every other recipe needs evidence the agent can read. Then debug the failures you have, add recovery where a dependency keeps failing, and finish with alerts so the next failure reaches you before a customer does.

For the incident process around a fix (paging, triage, the postmortem), read AI-powered incident response. For the principle that turns every production error into a regression test, read error-driven development.

Give the agent your error-handling rules before any recipe

Section titled “Give the agent your error-handling rules before any recipe”

Without rules, an agent optimizes for a quiet log: it swallows exceptions, adds optional chaining, and returns defaults for data that must exist. Write the rules once, where each tool loads them automatically.

## Error-handling rules
- Never swallow an error: no empty catch, no catch that only logs and continues,
no default value for data that must exist. Rethrow, or return a typed error.
- Classify every new catch: "expected sometimes" (handle it, log at warn) or
"should never happen" (fail loudly, log at error with context).
- Log with the project logger in structured form, with the request ID. Never log
tokens, passwords, cookies, or full request bodies.
- Every bug fix starts with a test or script that reproduces the bug and fails.
Never edit, skip, or loosen that test to make it pass.
- Retries only for idempotent calls, with a cap, backoff, and jitter.

Save the block as a project rule in .cursor/rules/, set to apply always. Keep the text identical to the other tools’ files so a change to the rules reaches every agent.

The “never loosen the test” rule matters most, and a rule alone is trust, not enforcement. Protecting the oracle shows how to make the reproduction test read-only for the agent.

How do you verify an agent’s error handling without reading every line?

Section titled “How do you verify an agent’s error handling without reading every line?”

Each recipe ends in a check a machine runs, and the pull request carries its output.

  • Red, then green. The reproduction fails on the unfixed code and passes after the fix. A test that never failed proves nothing.
  • The gates run in CI. The full suite, the type check, and lint run on the pull request, not only in the agent’s session.
  • A second agent reviews the diff against the diagnosis. Run /code-review in a Claude Code session, codex exec review --uncommitted in the terminal, or Bugbot on the pull request in Cursor, and ask it to look for hidden errors: new catches, loosened assertions, defaults on required data.
  • Production confirms the fix. After deploy, the error rate for that issue stays at zero through one traffic peak. The developer who shipped the fix checks it.

The developer owns the evidence; the tech lead approves when every item is present. For the full evidence table, see how to prove a bug fix without reading every line. For deliberate fault injection beyond one dependency, see error injection testing.