Estimate the Blast Radius

In the last exercise, you listed every function outside a diff that reads what the change touched. That list says where a change goes. Monday’s queue asks the next question: With five pull requests and one morning, which ones deserve your closest reading?

In this lesson, you’ll estimate a change’s blast radius: how much damage a faulty change could cause, and how much of that a revert would take back. You’ll write both down in map.md, so your triage rests on what each change reaches and what a revert leaves behind. Start with two changes that look very different in size.

Estimate Reach Before Size

A diff’s size tells you how long it takes to read, not the consequences of a faulty change. Picture two made-up pull requests, each starting from its intent.

The first answers Grace’s request for “a page that shows which books are running low.” It adds about 280 lines: a file under public/admin/ and a route in server.js that reads stock records and writes nothing. If it’s wrong, the staff desk shows an incorrect count, and nothing a customer sees or pays changes.

The second answers a request to “stop checkout crashing when a price has a decimal point.” It changes one line of src/lib/money.js, the shop’s shared money code:

Language: File Changes (diff)
diff --git a/src/lib/money.js b/src/lib/money.js
index 7b18fcc..133078e 100644
--- a/src/lib/money.js
+++ b/src/lib/money.js
@@ -1,6 +1,6 @@
 // Store pence. Only the display boundary knows about pounds or currency symbols.
 export function requirePence(value, label) {
-    if (!Number.isSafeInteger(value) || value < 0) {
+    if (!Number.isFinite(value) || value < 0) {
         throw new Error(label + ' must be a non-negative integer number of pence');
     }
     return value;

On main, requirePence() throws for any amount that isn’t a whole number of pence, because Number.isSafeInteger() rejects 7.5. The new Number.isFinite() accepts fractions, and whole numbers too large to add up exactly, such as 2 ** 53.

The request is about prices, but requirePence() checks every amount the shop handles. Whether the change does what was asked is for a later lesson. Here, ask how far it spreads if it’s wrong.

The principle for this lesson is to estimate reach before size. A change’s reach is everything that runs or depends on the changed code: its callers and the people behind them, whatever reads the data it writes, the money it moves, and anything that leaves the code, such as an email. One line in shared code can reach every request.

Check Every Reader of the Change

A guess such as “money code runs everywhere” can be too wide or too narrow, so search, as in Look Beyond the Diff. Start with the direct callers, the code that runs the changed line, found through the files that import its module. The made-up line isn’t in your clone, but the imports are:

Language: Shell
$ git grep -n -F "lib/money.js"
src/email/templates.js:1:import { formatPrice } from '../lib/money.js';
src/orders/pricing.js:2:import { requirePence } from '../lib/money.js';
src/payments/gateway.js:2:import { requirePence } from '../lib/money.js';
test/pricing.test.js:8:import { formatPrice } from '../src/lib/money.js';

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.