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).
Validate each batched/pipeline result instead of blanket-casting
Pipeline/batch results can each fail independently — check each entry's shape, log failures with context, and return a safe fallback instead of `as unknown as` over the whole array.
Bad example
| 1 | const results = await pipeline.execAsPipeline(); |
| 2 | // Blindly trusts every entry succeeded and has the expected shape |
| 3 | return results as unknown as { value: string; score: number }[][]; |
Explanation (EN)
execAsPipeline can return an Error in any slot (a single command failing). The blanket `as unknown as` cast hides those errors, and downstream code will crash or produce garbage when it treats an Error as the expected array.
Objašnjenje (HR)
execAsPipeline može vratiti Error u bilo kojem mjestu (ako pojedina naredba padne). Slijepi `as unknown as` cast skriva te greške, a kod nizvodno će puknuti ili dati smeće kad Error tretira kao očekivani niz.
Good example
| 1 | const results = await pipeline.execAsPipeline(); |
| 2 | return results.map((r, i) => { |
| 3 | if (Array.isArray(r)) return r as { value: string; score: number }[]; |
| 4 | logger.error(`[RedisService] pipeline command failed for key "${keys[i]}": ${r}`); |
| 5 | return []; |
| 6 | }); |
Explanation (EN)
Each result is checked individually; a failed command is logged with the offending key and replaced with an empty array, so one bad entry degrades gracefully instead of poisoning the whole batch.
Objašnjenje (HR)
Svaki rezultat se provjerava pojedinačno; neuspjela naredba se logira s ključem koji je problem i zamjenjuje praznim nizom, pa jedan loš unos lijepo degradira umjesto da zatruje cijelu skupinu.
Notes (EN)
Applies to any batch API where partial failure is possible: Redis pipelines/multi, Promise.allSettled, bulk DB writes, batched HTTP calls.
Bilješke (HR)
Vrijedi za svaki batch API gdje je moguć djelomični neuspjeh: Redis pipeline/multi, Promise.allSettled, skupni upisi u bazu, grupirani HTTP pozivi.