Skip to content

fix(logger): actually verify pino-pretty is installed before configuring it#138

Merged
CryptoJones merged 1 commit into
masterfrom
fix/logger-pino-pretty-availability-check
May 19, 2026
Merged

fix(logger): actually verify pino-pretty is installed before configuring it#138
CryptoJones merged 1 commit into
masterfrom
fix/logger-pino-pretty-availability-check

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Closes #137.

Summary

The existing try block around the transport = { target: 'pino-pretty', … } assignment was a no-op — object-literal construction doesn't throw. Pino lazy-resolves the target module the first time the logger emits, so a deployment that sets LOG_PRETTY=1 without pino-pretty on disk crashes on first log line (often during DB init seconds into startup) with a confusing pino-internal error. The "fall through to JSON output" path the comment promised never ran.

Insert an explicit require.resolve('pino-pretty') inside the try block. require.resolve synchronously throws MODULE_NOT_FOUND when the module is missing, so the catch fires cleanly and transport stays undefined — pino then falls through to default JSON output, matching the "pino-pretty is NOT a required dependency" comment at the top of the file.

Test plan

  • npm run lint — clean
  • npm test — 495 passed, 15 skipped (no test count change; existing logger tests pin the loaded-module case)
  • No new regression test: exercising the missing-pino-pretty branch requires either a subprocess spawn (heavyweight) or filesystem mocking that interacts with Node's module loader (brittle); the change is a behavior-correctness fix that brings the code in line with what the comment already promised

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

…ing it

The existing `try` block around the `transport = { target: 'pino-pretty', … }`
assignment was a no-op. Object-literal construction doesn't throw —
pino lazy-resolves the `target` module the first time the logger emits,
which means a deployment that sets `LOG_PRETTY=1` without `pino-pretty`
on disk would crash on first log line (often during DB-init logging,
seconds into startup) with a confusing pino-internal error. The
"fall through to JSON output" path the comment promised never ran.

Insert an explicit `require.resolve('pino-pretty')` inside the try
block. `require.resolve` synchronously throws MODULE_NOT_FOUND when
the module is missing, which lets the catch fire and the transport
stay undefined — so pino falls through to default JSON output, which
is what the operator should see when they ask for pretty output but
haven't installed the (optional) dev dependency.

No test added because exercising the missing-pino-pretty branch
requires either a subprocess spawn (heavyweight) or filesystem
mocking that interacts with Node's module loader (brittle); the
existing logger tests verify the loaded-module case and continue to
pass. The change is a behavior-correctness fix that brings the code
in line with what the comment already promised.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit 53714e9 into master May 19, 2026
3 checks passed
@CryptoJones CryptoJones deleted the fix/logger-pino-pretty-availability-check branch May 19, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logger: LOG_PRETTY=1 crashes on first log line when pino-pretty isn't installed

1 participant