Error handling and failure paths in AI code
For engineers
AI code favours the happy path: swallowed errors, silent fallbacks, missing timeouts, unsafe retries, races and forgotten edge inputs
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
An AI-written function returns 0 when the ledger call fails with any exception. What is the main risk?
Check yourself · 2 of 5
Why is a retry around a payment request dangerous without an idempotency key?
Check yourself · 3 of 5
Two users book the last seat at the same time and both succeed. Which pattern in the code caused it?
Check yourself · 4 of 5
An AI function averages a list by dividing the sum by the length. Which input breaks it?
Check yourself · 5 of 5
A function reduces stock, then charges a card, and the charge fails. What is the best structure?
Topics
- Swallowed errors and silent fallbacks5 min read · Catch-all blocks, default values that hide failures and log-and-continue handlers common in generated code
- Timeouts, retries and idempotency5 min read · Network calls with no timeout, retries that send a payment or email twice, and backoff with jitter done right
- Race conditions in generated code5 min read · Check-then-act, shared mutable state and missing transactions or locks that agents rarely consider
- Edge-case inputs AI code forgets5 min read · Empty lists, nulls, Unicode, time zones, huge numbers and partial data that break the happy path
- Partial failure and resource cleanup5 min read · Half-written state after a crash, unclosed connections and files, and cleanup with transactions and finally blocks
Start here
- Making retries safe with idempotent APIs (Amazon Builders' Library) (opens in a new tab)ArticleFree
How idempotency tokens let a client retry a request without doing the work twice.
- Timeouts, retries and backoff with jitter (AWS Builders' Library) (opens in a new tab)ArticleFree
Why every remote call needs a timeout and how capped backoff with jitter avoids retry storms.
- Error Handling Cheat Sheet (OWASP) (opens in a new tab)DocsFree
Handle errors centrally, fail safely and log enough detail without leaking it to users.
Helps to know first
110 questions · last verified 2026-12