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).
Guard JSON.parse when deserializing batches so one bad record cannot break all
Wrap per-record JSON.parse in try/catch and quarantine the corrupt entry instead of letting it abort the whole batch.
Bad example
| 1 | for (let i = 0; i < ids.length; i++) { |
| 2 | const raw = values[i]; |
| 3 | // One corrupt value throws and aborts the entire load |
| 4 | state[ids[i]] = JSON.parse(raw) as Entry; |
| 5 | } |
Explanation (EN)
A single malformed stored value makes JSON.parse throw, which fails the whole load and freezes every future regeneration until the bad record is removed by hand.
Objašnjenje (HR)
Jedna neispravna pohranjena vrijednost izazove bacanje JSON.parse, što sruši cijelo učitavanje i zamrzne svaku buduću regeneraciju dok se loš zapis ručno ne ukloni.
Good example
| 1 | for (let i = 0; i < ids.length; i++) { |
| 2 | const raw = values[i]; |
| 3 | try { |
| 4 | state[ids[i]] = JSON.parse(raw) as Entry; |
| 5 | } catch { |
| 6 | staleIds.push(ids[i]); // quarantine and clean up later |
| 7 | } |
| 8 | } |
Explanation (EN)
Catching the parse error per record isolates the failure, lets the rest load, and schedules the corrupt entry for cleanup.
Objašnjenje (HR)
Hvatanje greške parsiranja po zapisu izolira kvar, omogući učitavanje ostatka i zakaže loš zapis za čišćenje.