Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: TypeScript
error-handlingloopsresilience
Wrap the whole loop iteration in try/catch, not just the tail
When iterating and you want per-item resilience, the try/catch should cover the full iteration body so an early failure doesn't skip later steps or break the loop.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | for (const item of items) { |
| 2 | const mapped = map(item); // unprotected |
| 3 | try { |
| 4 | await save(mapped); |
| 5 | } catch (e) { log(e); } |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | for (const item of items) { |
| 2 | try { |
| 3 | const mapped = map(item); |
| 4 | await save(mapped); |
| 5 | } catch (e) { log(e); } |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)