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).
fullstack ruleP1universalStack: typescript
error-handlingapi-designutilities
Avoid throwing from pure utilities that callers must wrap in try/catch
A general-purpose helper that throws forces every call site into a try/catch; prefer returning a safe empty/sentinel value or validating at the boundary unless failure is truly exceptional.
PR: hegnar-zephr-components · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codets
| 1 | function chunk(items, size) { |
| 2 | if (size <= 0) throw new Error('size must be > 0'); |
| 3 | // ... |
| 4 | } |
| 5 | // every caller now needs try/catch |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | function chunk(items, size) { |
| 2 | if (size <= 0) return []; |
| 3 | // ... |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)