Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Route to a fallback data source via a capability check, not try/catch
Use capability checks for deliberate routing and typed failure handling for runtime failures; availability checks do not eliminate races.
Bad example
| 1 | async fetchPriceHistory(token, query) { |
| 2 | try { |
| 3 | // assume primary works; if it throws, fall through |
| 4 | return await this.primary.fetch(query); |
| 5 | } catch (e) { |
| 6 | // swallows genuine bugs (timeouts, mapping errors) as 'unavailable' |
| 7 | return this.fallback.fetch(token, query); |
| 8 | } |
| 9 | } |
Explanation (EN)
A blanket catch treats every primary failure as a reason to use fallback.
Objašnjenje (HR)
Opći catch tretira svaki kvar primarnog izvora kao razlog za fallback.
Good example
| 1 | async fetchPriceHistory(token, query) { |
| 2 | const period = query.period.toUpperCase(); |
| 3 | const isIntraday = period === '1D' || period === '5D'; |
| 4 |
|
| 5 | // primary only handles non-intraday and only when it is up |
| 6 | if (!isIntraday && this.primary.isAvailable()) { |
| 7 | return this.fetchFromPrimary(query, period); |
| 8 | } |
| 9 | return this.fetchFromFallback(token, query, period); |
| 10 | } |
Explanation (EN)
Capability and domain checks make source selection explicit. The chosen source can still fail after the check, and its errors need an intentional propagation or recovery policy.
Objašnjenje (HR)
Provjere sposobnosti i domene čine odabir izvora izričitim. Odabrani izvor i dalje može pasti nakon provjere, pa njegove pogreške trebaju namjernu propagaciju ili oporavak.
Notes (EN)
Route using stable capability/domain information when available, and still define what happens if the selected operation fails after that check.
Exceptions / Tradeoffs (EN)
Availability can change between check and call. Catching specific retryable failures can be appropriate; do not retry non-idempotent work or hide programmer/authentication errors.
Iznimke / Tradeoffi (HR)
Dostupnost se može promijeniti između provjere i poziva. Obrada konkretnih ponovljivih kvarova može biti ispravna; ne ponavljaj neidempotentan posao niti skrivaj programske ili autentifikacijske pogreške.