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

Closed
Tiim opened this issue Jun 27, 2019 · 2 comments
Closed

Crash when logging date #72

Tiim opened this issue Jun 27, 2019 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Tiim
Copy link

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:

/code/node_modules/pino-pretty/lib/utils.js:178
   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());
console.log(value);

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 😅

@mcollina
Copy link
Member

mcollina commented Jun 27, 2019 via email

@jsumners
Copy link
Member

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

pino-pretty/index.js

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:

pino-pretty/index.js

Lines 68 to 70 in a6b2032

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

@jsumners jsumners added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants