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

PrettyPrint fails when error's stack is null #382

Closed
grbr opened this issue Mar 30, 2018 · 7 comments
Closed

PrettyPrint fails when error's stack is null #382

grbr opened this issue Mar 30, 2018 · 7 comments
Labels

Comments

@grbr
Copy link
Contributor

grbr commented Mar 30, 2018

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

@jsumners
Copy link
Member

Did this work correctly in 4.14.0?

@davidmarkclements
Copy link
Member

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

@jsumners
Copy link
Member

Ugh, I need to get the CLI revamp done.

@mcollina
Copy link
Member

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

@jsumners jsumners added the bug label Mar 30, 2018
@grbr
Copy link
Contributor Author

grbr commented Apr 2, 2018

i've added pull request

mcollina pushed a commit that referenced this issue Apr 3, 2018
* fix issue #382 pretty print error with null stack

* prints stack: "null" when error is a property

* errors with a null stack, #382
@grbr grbr closed this as completed Apr 3, 2018
jsumners added a commit that referenced this issue Apr 13, 2018
* Issue #382, pretty print error with null stack (#383)

* fix issue #382 pretty print error with null stack

* prints stack: "null" when error is a property

* errors with a null stack, #382

* Bumped v4.15.4.

* added lastTime meta parameter (#385)

* Bumped v4.16.0.

* Remove CLI and add robust prettifier support

* Use required prettifier directly and tweak documentation

* Address documentation concerns

* Remove chalk

* Add bin with deprecation notice

* Add URL to deprecation notice

* deprecated => removed

* Move split2 to dev dependencies

* Move asMetaWrapper into Pino and update pretty docs
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants