Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when logging date #72

Tiim opened this issue Jun 27, 2019 · 2 comments


Copy link

@Tiim Tiim commented Jun 27, 2019

When i directly log JSON.stringified date with console.log without using pino then peno-pretty crashes with the following error message:

   if ('level' in log === false) return undefined

 TypeError: Cannot use 'in' operator to search for 'level' in 2019-05-31T00:00:00.000Z
     at prettifyLevel (/code/node_modules/pino-pretty/lib/utils.js:178:15)
     at pretty (/code/node_modules/pino-pretty/index.js:85:29)
     at Transform.transform [as _transform] (/code/node_modules/pino-pretty/bin.js:38:18)
     at Transform._read (/code/node_modules/pino-pretty/node_modules/readable-stream/lib/_stream_transform.js:177:10)
     at Transform._write (/code/node_modules/pino-pretty/node_modules/readable-stream/lib/_stream_transform.js:164:83)
     at doWrite (/code/node_modules/pino-pretty/node_modules/readable-stream/lib/_stream_writable.js:405:139)
     at writeOrBuffer (/code/node_modules/pino-pretty/node_modules/readable-stream/lib/_stream_writable.js:394:5)
     at Transform.Writable.write (/code/node_modules/pino-pretty/node_modules/readable-stream/lib/_stream_writable.js:303:11)
     at Transform.ondata (/code/node_modules/split2/node_modules/readable-stream/lib/_stream_readable.js:662:20)
     at Transform.emit (events.js:196:13)

The following snipped in my code (fastify server) will produde this crash:

const value = JSON.stringify(new Date());

I have not tested if this only works with stringified dates or if this is a bug when a string with start and end "quotes" gets logged.

I know this is already my second crash report, but apparently I'm a talent for finding crash bugs in pino-pretty 😅


This comment has been minimized.

Copy link

@mcollina mcollina commented Jun 27, 2019


This comment has been minimized.

Copy link

@jsumners jsumners commented Jun 27, 2019

A plain string is valid JSON, thus it gets past the check:


Lines 56 to 65 in a6b2032

if (!isObject(inputData)) {
const parsed = jsonParser(inputData)
log = parsed.value
if (parsed.err) {
// pass through
return inputData + EOL
} else {
log = inputData

Probably need another isObject check after JSON parsing to determine if we can go forward at:


Lines 68 to 70 in a6b2032

if ([null, true, false].includes(log) || Number.isFinite(log)) {
return `${log}\n`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.