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).
Log the crash path through the immediate-emit logger, never a buffered or context-folding one
A logger variant that enriches a pending request event instead of writing right away produces no output when the process exits, so use the direct-emit API in crash, shutdown, and fatal paths.
Bad example
| 1 | process.on("uncaughtException", (error) => { |
| 2 | logger.fatal("uncaught exception", { error }); // folds into the active request event |
| 3 | process.exit(1); // nothing was ever written |
| 4 | }); |
Explanation (EN)
The folding variant only mutates the in-flight request event, which is emitted by a response hook that never runs because the process is already exiting.
Objašnjenje (HR)
Varijanta koja spaja zapise samo mijenja dogadaj zahtjeva u tijeku, a njega emitira hook odgovora koji se nikad ne izvrsi jer se proces vec gasi.
Good example
| 1 | process.on("uncaughtException", (error) => { |
| 2 | emitFatal("uncaught exception", { error }); // writes synchronously, bypasses the request context |
| 3 | void flushAndExit(1); |
| 4 | }); |
Explanation (EN)
The direct-emit call writes the line before the exit, so the restart leaves a diagnostic behind.
Objašnjenje (HR)
Poziv koji emitira izravno zapisuje liniju prije gasenja, pa restart iza sebe ostavlja dijagnostiku.
Notes (EN)
Wide-event loggers usually ship two families: enrich-the-current-event helpers and emit-now helpers. Anything that runs outside or at the end of a request lifecycle needs the second family.
Bilješke (HR)
Loggeri sa sirokim dogadajima obicno nude dvije obitelji funkcija: one koje obogacuju trenutni dogadaj i one koje odmah emitiraju. Sve sto se izvrsava izvan ili na kraju zivotnog ciklusa zahtjeva treba drugu obitelj.