Pino: PrettyPrint fails when error's stack is null

Created on 30 Mar 2018  路  6Comments  路  Source: pinojs/pino

Hello!

I try to log an object like this:

// just an object with property 'error'
var obj = { data: 'bla', error: { message: 'bla error', stack: null } }
prettyPino.info(obj)

and i get an error:

TypeError: Cannot read property 'length' of null
    at filter (node_modules/pino/pretty.js:87:23)
    at DestroyableTransform.mapLine [as mapper] (node_modules/pino/pretty.js:251:15)
    at DestroyableTransform.transform [as _transform] (node_modules/split2/index.js:33:21)
    at DestroyableTransform.Transform._read (node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (node_modules/readable-stream/lib/_stream_writable.js:418:64)
    at writeOrBuffer (node_modules/readable-stream/lib/_stream_writable.js:407:5)
    at DestroyableTransform.Writable.write (node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at EventEmitter.pinoWrite (node_modules/pino/pino.js:220:12)
    at EventEmitter.LOG (node_modules/pino/lib/tools.js:93:10)
...

In pretty.js null is a matches for

var matches = /^(\s*"stack":)\s*"(.*)",?$/.exec(line)

'length' of null is

if (matches.length === 3) {

Please add null check
Best regards

bug

Most helpful comment

Ugh, I need to get the CLI revamp done.

All 6 comments

Did this work correctly in 4.14.0?

just checked - works correctly in 4.14.0 - error introduced in 4.15.0

Ugh, I need to get the CLI revamp done.

Anyway, this can be easily fixed with a small patch, @grbr would you like to do the honors?

i've added pull request

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ronag picture ronag  路  5Comments

acro5piano picture acro5piano  路  3Comments

davidmarkclements picture davidmarkclements  路  6Comments

JamesKyburz picture JamesKyburz  路  7Comments

callumlocke picture callumlocke  路  4Comments