A technical write-up of the NASA bug, ready to paste. DEV requires AI-assisted posts to say so and forbids them from promoting a business, so it ends with a disclosure line and carries no pitch. Your LinkedIn already told this story on 1 Oct, so don't repost it there.
Title: A silent || 4.0 gave every place on Earth the same sunshine
Tags: typescript, javascript, testing, debugging
My solar calculator once told Fuengirola in Spain and Tétouan in Morocco that they would save exactly the same energy: 4,203 kWh a year, €1,050.70. The response said the irradiance came from NASA. It didn't.
The bug
NASA POWER returns monthly values keyed YYYYMM: 202201, 202202, and so on. My code built its keys from a list of month names, so it asked for 2022JAN. All twelve lookups missed.
The read had defaults: || 4.0 for irradiance and || 15.0 for temperature. Each miss quietly became 4.0, so every location on Earth got the same twelve numbers, and the response still reported live NASA data.
Nothing crashed and nothing logged. The numbers looked plausible, and that is the problem: once a plausible default is in the output, nobody can tell it from data.
The fix, and what it found
With the key format fixed, Fuengirola came out at 3,702 kWh and Tétouan at 3,786 kWh for 2022. The old figure was 13.5% too high for Fuengirola.
The same response held two more traps:
• NASA POWER marks a month with no data as -999. That value is finite, so Number.isFinite, the only guard the code had, accepted it as an irradiance reading. The code now compares against the documented fill value exactly.
• NASA appends a thirteenth key, YYYY13, holding the annual mean. Reading the months off Object.keys() would give thirteen entries and a wrong annual figure. The month list is now explicit.
The rule it left
A missing input is reported as missing, never replaced by a plausible number. In practice:
• When NASA POWER can't be used, the calculator answers with a typed 503, nasa_unavailable, and no figure, instead of estimating from latitude.
• When a country has no official tariff, the money line shows "pending".
• The tests that pin this run against responses captured from live NASA POWER and Nominatim, so they still mean something without a network.
What to check in your own code
Search for || and ?? on anything read from an external API. Each one is a place where a failed lookup can turn into a confident answer. Ask whether the caller would rather get the default or an error. In my case the honest answer was always the error.
The fix and its tests are public: https://github.com/elmaroun07-hub/voltura (see artifacts/api-server/src/routes/calculate.test.ts).
Drafted with AI help; every number was checked against the repo.
Backend
Source:https://dev.to/houssain_elmarouni_09942/a-silent-40-gave-every-place-on-earth-the-same-sunshine-hgo
A silent || 4.0 gave every place on Earth the same sunshine
dev.to JavaScript0 views
PreviousWriting a JavaScript Fee Engine to Protect My Etsy MarginsNextReject Unsafe Integer Quantities Before Summing an Order Import
Related posts
API Pagination Cursor Expired Mid-Run in an Agent Tool
0dev.to
10 Codex Plugins You Wish You Knew Sooner (All Checked)
0dev.to
Prompt Injection Becomes Serious When Authorization Trusts the Model
0dev.to
WebSockets Explained: Real-Time Data Without Polling
0dev.to
My AI Math Tutor Started Making Up Pictures Instead of Drawing Them
0dev.to
gRPC Explained: APIs That Speak in Binary
0dev.to