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).
Only throw (or reject) Error objects
Throwing non-Errors loses stack traces and makes debugging harder.
Bad example
| 1 | throw 'oh no'; |
| 2 |
|
| 3 | Promise.reject('bad'); |
Explanation (EN)
Throwing strings/objects can lose stack trace information and leads to inconsistent error handling.
Objašnjenje (HR)
Bacanje stringova/objekata može izgubiti stack trace i vodi do nekonzistentnog error handlinga.
Good example
| 1 | throw new Error('oh no'); |
| 2 |
|
| 3 | Promise.reject(new Error('bad')); |
Explanation (EN)
Using Error (or subclasses) preserves stack traces and standardizes error handling across codebases.
Objašnjenje (HR)
Korištenje Error-a (ili podklasa) čuva stack trace i standardizira error handling kroz codebase.
Notes (EN)
When catching unknown, narrow to Error (e.g., asserts) rather than defensive handling of random types.
Bilješke (HR)
Kad catchaš unknown, suzi na Error (npr. asserts) umjesto obrane od svih mogućih tipova.
Exceptions / Tradeoffs (EN)
Only when integrating with a known bad API that throws non-Errors; add a comment identifying the source.
Iznimke / Tradeoffi (HR)
Samo kad integriraš poznati loš API koji baca non-Error; dodaj komentar koji identificira izvor.