Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Filter non-finite numbers out before they reach a query clause
An unguarded numeric conversion turns a missing or malformed id into NaN, which most JSON serializers write as null. The search or database backend then rejects the whole query, so one bad row fails the entire response instead of quietly losing its own enrichment.
Bad example
| 1 | const ids = new Set( |
| 2 | articles.flatMap((a) => a.tags.map((t) => Number(t.externalId))), |
| 3 | ); |
| 4 | await provider.byIds([...ids]); // terms: { ref: [NaN] } -> serialized as null -> 400 |
Explanation (EN)
A single malformed tag id poisons the request for every article in the batch.
Objašnjenje (HR)
Jedan neispravan id oznake pokvari zahtjev za sve clanke u seriji.
Good example
| 1 | const ids = new Set( |
| 2 | articles.flatMap((a) => |
| 3 | a.tags |
| 4 | .map((t) => Number(t.externalId)) |
| 5 | .filter((id) => Number.isFinite(id) && id > 0), |
| 6 | ), |
| 7 | ); |
| 8 | await provider.byIds([...ids]); |
Explanation (EN)
Bad values are dropped at the boundary, so a malformed row costs only its own enrichment.
Objašnjenje (HR)
Lose vrijednosti odbacuju se na granici, pa neispravan redak kosta samo vlastito obogacivanje.
Notes (EN)
Watch for this when a refactor stops re-stringifying values. Passing junk through as a string only fails to match; passing it through as NaN fails the query.
Bilješke (HR)
Pripazi na to kad refaktoriranje prestane pretvarati vrijednosti natrag u string. Smece proslijedeno kao string samo se ne podudara; smece proslijedeno kao NaN rusi upit.