Lesson 8 of 14 · 20m
The Error Path Is a Real Path
Failures don't queue politely — classify caller, transient, and bug errors, and design what happens on each path.
Run JSON.parse(req.body) on a public endpoint. Most days it parses. The day it doesn't, it throws a SyntaxError — and if nothing caught it, Express answers 500, or the process dies. Since Node 15, an unhandled promise rejection crashes the process by default; before that it printed a warning everyone ignored, which is exactly why the default changed. The happy path is one path among many. Failures don't queue politely waiting for you to notice.
The two wrong mental models: "catch everything to be safe" — try { ... } catch (e) {} converts loud failures into silent wrongness, and silent-wrong is the most expensive state a system can be in — and "errors are exceptional, edge events." At a million requests a day, a 1-in-10,000 failure is a hundred daily events.
Classify first, handle second
Errors sort into three kinds, and each wants a different response:
- Caller errors — bad input, malformed JSON, missing field. Deterministic, the caller's fault: answer a 400-class status with a message that says what's wrong. Never retry; retrying bad input just fails slower.
- Transient/system errors — a timeout,
ECONNRESET, a 503 from upstream. Worth retrying, with exponential backoff and jitter — Marc Brooker's 2015 AWS architecture post on backoff-and-jitter is the canonical write-up, because retries synchronized across clients become a second outage. - Programmer errors — null dereference, violated invariant, unreachable code that was reached. This is a bug: fail fast and loud so it surfaces in monitoring. Don't retry a bug.
Retry storms are a second outage
"Just retry it" deserves precision, because naive retries amplify a failure. Exponential backoff — wait 1s, then 2s, then 4s — caps how hard you hammer a struggling upstream. Jitter — randomizing each client's wait — is what stops a thousand clients who all failed at the same instant from retrying at the same instant. Without it, your retry policy becomes the second outage.
Errors as values vs. exceptions
Go made the error a return value — if err != nil looks verbose until you realize the verbosity is the point: handling is a decision you make at each hop, in the same syntax as the rest of the code. Rust's Result<T, E> with the ? operator makes ignoring an error a compile-time decision you have to write down as .unwrap(). C's errno and unchecked scanf return values are the historical counterexample — errors exist but the language won't make you look at them, which is how silent wrongness happens. Java's checked exceptions were the same idea done loudly; the debate about them is itself the lesson: the contract exists whether you design it or not.
Write the message for the person debugging it
An error message has an audience, and it isn't the user — it's whoever is debugging at 3am, which is usually you. ECONNREFUSED 10.0.0.4:5432 tells an operator exactly what to check; Internal server error tells them nothing. Same failure, different incident length. Actionable errors are a feature: "retry in 30s," "token expired — re-authenticate," "field email must be a valid address."
The error path needs tests too
It isn't handled until you've seen it fail correctly. Mock the database to throw, use nock or msw to fail the HTTP call, and assert the classified response — the 400 for bad input, the retry for the transient, the surfaced error for the bug. "It threw something" is not a test result.
Try it yourself — classify, in JS
function handle(e) {
if (e.name === "SyntaxError") return { status: 400, retry: false }; // caller error
if (e.code === "ECONNRESET") return { status: 503, retry: true }; // transient
return { status: 500, retry: false, alert: true }; // bug: surface it
}
console.log(handle(new SyntaxError("bad json"))); // -> 400, don't retry
console.log(handle({ name: "Error", code: "ECONNRESET" })); // -> 503, retryThe practice
Classify every error your code can produce, design the response per class, and make messages actionable — "retry in 30s," not "oops." catch is where behavior goes to be designed, not deleted.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
systemd Added Rust by Refusing Almost Everything Rust Offers
The headline was "systemd adopts Rust." The commit, which I read in the tree, rejects most of how Rust is normally used: no standard library, no cargo, no crates, no rewrites, no Rust in shared libraries. The reasoning is a quiet argument about where systemd's real attack surface is.
Next.js Shipped Seven Advisories and Six of Them Are the Cache
The November 2026 Next.js security release patches seven issues, and six live in the new Cache Components layer, the feature meant to make your app faster by remembering more. Three hit self-hosted next start specifically: the ones Vercel's own platform quietly absorbs.
The Same Researcher Broke apt the Same Way Twice, Seven Years Apart
In 2019 Max Justicz showed apt would install a package an attacker swapped in over a redirect. In November 2026 he did it again, CVE-2026-109518, through a different door that ends in the same place: code as root from a man in the middle. The fix shows how apt reuses files on disk.
Java Pulled Primitive Patterns After Five Previews. JDK 28 Won't Compile Them.
Primitive types in patterns, instanceof, and switch previewed in every JDK from 23 to 27. On November 9 the Amber team withdrew the feature, and it won't be in JDK 28 even with --enable-preview. Here's why Valhalla changed the plan, what replaces it, and how to rewrite code that used it.