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
api-designbulk-operationserror-reporting
Return bulk results aligned with the input so callers know what failed
For bulk-create style operations, return an array the same length as the input (with null for skipped/failed items) so the caller can map results back by index.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | // only successful items returned; caller can't tell which failed |
| 2 | function bulkCreate(items: Dto[]): Note[] { |
| 3 | return items.map(create).filter(Boolean); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // same length as input, null marks the ones that weren't created |
| 2 | function bulkCreate(items: Dto[]): (Note | null)[] { |
| 3 | return items.map((i) => (canCreate(i) ? create(i) : null)); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)