A phone app for resellers works like this: scan an item, see what it sells for, and tap to add it to a queue of items waiting to be listed for sale. A server stores the queue. A background sweep and a web page work through it.
One line on one screen turned “we do not know the price” into “the price is zero”. Every part of the system after it believed that, and none of them was wrong on its own.
Key facts
- The detail screen fell back to 0 when the market had no offer for an item.
- The server stored that 0 as the price, one row per condition the user had chosen. Such a row can never be listed.
- 777 such rows across 21 accounts over about five months; about 390 in the last 30 days, 237 of those from one account.
- The fix refuses the add on the server, with no app release.
What happened
The detail screen computes the item’s best selling price from the offers on a marketplace. Some items have no offer at all. For those, the code fell back to zero:
const price = getBestSellPrice(item) ?? 0
It was written so the screen had a number to show. The trouble is that the number did not stay on the screen.
What the zero did
The “add to queue” call sent the 0 to the server. The server stored it as the row’s price, one row for each condition the user had chosen. Nothing in between asked whether 0 was a price or a missing price.
From there, the row was stuck. The submit step skipped rows with no price, so it never went out. A background sweep then filed each one as an issue with this text:
“Cannot list this item: no sell price on the scan. Delete it and re-scan.”
Re-scanning gives 0 again, because the market still has no offer. The web page had a Retry button for the issue. It only re-filed the row about 4 hours later with the same text.
So the user got an instruction that could not work, a retry that could not work, and a queue that slowly filled with rows that looked like work to do.
Why nobody saw it
Each layer behaved correctly on its input. The screen showed $0. The server stored the number it was given. The submit step skipped a row with no price. The sweep reported it. The message was even true: there was no sell price.
Only the chain was wrong, and its first link was a default.
It is a cousin of a safety check that read a value one rule never set: there, nothing was read as an answer. Here, nothing was written down as an answer before anyone read it.
The count
Before changing anything, we counted the bad state in production with read-only queries. The result: 777 such rows across 21 accounts over about five months. About 390 of them were from the last 30 days, and 237 of those came from one account.
Almost all of them had a stored price of exactly 0.00. They were very slow-selling items, with negative profit and no offers.
The count mattered. It showed a pattern, not one odd row. It also gave the fix its test: the same kind of add, after the fix, must not create a row.
The fix
The fix has three small parts, and none of them needs an app release:
- The server refuses an add that has no positive price for any chosen condition. It answers HTTP 422 with a plain reason that the screens already display. Conditions that do have a price are still added.
- The sweep’s text no longer tells people to re-scan.
- The web page shows such rows as “No price”, with a plain summary and no Retry button. Delete and the other actions stay.
The phone still sends 0. The server now says no. A sketch, with made-up names:
// Screen: a number to show, even when there is none.
const price = bestSellPrice(item) ?? 0;
addToQueue({ itemId: item.id, conditions, price });
// Server, before: stores whatever came in.
app.post('/queue', async (req, res) => {
const { itemId, conditions, price } = req.body;
for (const c of conditions) {
await db.insert({ itemId, condition: c, price });
}
res.json({ accepted: true });
});
// Server, after: no price is a refusal, not a 0.
app.post('/queue', async (req, res) => {
const { itemId, conditions } = req.body;
const priced = conditions.filter(c => priceFor(req.body, c) > 0);
if (!priced.length) {
return res.status(422).json({ accepted: false, reason: 'no_price' });
}
for (const c of priced) {
await db.insert({ itemId, condition: c, price: priceFor(req.body, c) });
}
res.json({ accepted: true, added: priced.length });
});
We checked it without writing anything. The real server handler was called for a test account three times: with price 0, with no price at all, and with 0 plus the “automatic” flag. Every database query that was not a read was set to fail. All three calls were refused with the new message, and no write was even attempted.
The 777 old rows keep their stored text. And one line went into the project’s list of things that must stay true: an add with no price is refused, never stored as 0.
The checklist
Anyone can do these tomorrow:
- Search for quiet defaults. Look for
?? 0,|| 0,?? ''and|| []on values that cross a boundary: sent to a server, stored, or used in a decision. Display-only defaults are fine; stored ones are not. - Validate at the boundary that stores. Not at the screen that shows. The server should refuse “price 0” for something that must have a price, with a reason a person can read.
- Do not prescribe a step that reproduces the error. Before shipping “delete it and try again”, ask what trying again will return.
- Offer Retry only on failures that can change. For a permanent condition, show the reason and the actions that do help.
- Count the bad state before fixing. One read-only query in production tells you whether it is one odd row or a pattern, and gives the fix its test.
- Write the rule down. One line, where reviewers will see it.
The lesson in one line: a default is a claim. ?? 0 says “when I do not know, the answer is zero”, and every layer after it will believe that. For money, quantity, time and ids, unknown must stay unknown (null, a missing field, a refusal) until something that can decide sees it.
Common questions
Is ?? 0 always wrong?
No. A zero that is only shown on a screen is fine. It becomes wrong once the value leaves the screen: sent to a server, stored, or used in a decision. From there on, everything that reads it believes it.
Why refuse on the server instead of fixing the screen?
The server is the boundary that stores. Every client passes through it. The phone still sends 0; the server now says no, and no app release was needed.
Melta is free; get it on the App Store or Google Play.