Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Preserve the original error when logging or re-throwing
Don't discard the caught error. Include its message (and stack/cause) in the log and in any wrapper error so failures stay diagnosable.
Bad example
| 1 | try { |
| 2 | await connectToRedis(); |
| 3 | } catch (error) { |
| 4 | logger.error('Failed to connect to Redis'); |
| 5 | throw new Error('Failed to connect to Redis'); |
| 6 | } |
Explanation (EN)
Both the log line and the thrown error throw away the original error, so there is no message, stack, or root cause to debug from — every failure looks identical.
Objašnjenje (HR)
I log linija i bacena greska odbacuju originalnu gresku, pa nema poruke, stacka ni korijenskog uzroka za debugiranje — svaki kvar izgleda identicno.
Good example
| 1 | try { await releaseLease(); } |
| 2 | catch (error) { logger.warn('Lease release failed', describeSafeError(error)); } |
Explanation (EN)
The shared classifier retains an allowlisted reason and status without logging request credentials or replacing the original operation outcome.
Objašnjenje (HR)
Zajednicki classifier cuva dopusteni razlog i status bez tajni i bez promjene rezultata glavne operacije.
Notes (EN)
In best-effort cleanup or lease release, keep a structured sanitized diagnostic for the caught error while preserving the primary outcome. Use a shared allowlisted classifier or proven redaction rather than logging raw client errors that may contain credentials, request headers or payloads. Test diagnostic fields and absence of synthetic secrets. Sanitized validation diagnostics must preserve the safe schema field path and error category. Test real validator exceptions through the runtime classifier, including root-level failures, rather than only constructing a different validation-error class in tests.
Bilješke (HR)
Greska cleanupa ili otpustanja leasea treba sigurne dijagnosticke podatke bez promjene glavnog ishoda. Koristi zajednicki sanitizer i ne zapisuj sirove klijentske greske s tajnama.
Exceptions / Tradeoffs (EN)
When deliberately mapping an internal error to a sanitized client-facing message, keep the original in server logs/cause but do not leak it in the API response.
Iznimke / Tradeoffi (HR)
Kad namjerno mapirate internu gresku u sanitiziranu poruku za klijenta, zadrzite original u server logovima/cause-u ali ga ne otkrivajte u API odgovoru.