Invental/Review lessons/Code that silently does the wrong thing

Code that silently does the wrong thing

A bare ?dryRun flag must mean on

Parse safety flags so that their presence means “on”. Then ?dryRun with no value does a preview and never writes.

01 · Before and afterThe pattern

TypeScript
// before: toBoolean('') === false, so "?dryRun" runs a real import
const dryRun = toBoolean(req.query.dryRun);
// after: presence means on; "?dryRun=false" still turns it off
const flag = (v: unknown) => v === '' || toBoolean(v);
const dryRun = flag(req.query.dryRun);

02 · Run it on your appThe check

If someone calls your destructive endpoint with ?dryRun and no value, does it write anything?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.