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

Invalid error JSON logged if stack is undefined #456

Closed
disintegrator opened this issue Jul 20, 2018 · 7 comments · Fixed by #457
Closed

Invalid error JSON logged if stack is undefined #456

disintegrator opened this issue Jul 20, 2018 · 7 comments · Fixed by #457

Comments

@disintegrator
Copy link
Contributor

disintegrator commented Jul 20, 2018

To reproduce:

const logger = require('pino')();
const err = new Error();
delete err.stack;
logger.error(err);

/*
{"level":50,"time":1532087320790,"msg":"","pid":20631,"hostname":"dev.local","type":"Error","stack":undefined,"v":1}
*/

Note the section "stack":undefined which is not valid JSON.

Real world example: Apollo GraphQL has a custom error class called ApolloError that does not hold stack property. When logging an ApolloError we see the issue above which breaks pino's pretty printer among other things.

Pino version: 4.17.3

@mcollina
Copy link
Member

That’s definitely a bug! Out of curiosity.. why are you removing .stack?

@disintegrator
Copy link
Contributor Author

disintegrator commented Jul 20, 2018

Hey @mcollina. Thanks for the quick reply. The code attached is strictly a way to reproduce the issue. The real world case affecting me is trying to log instances of ApolloError which are an instance of Error but do not have a stack property set for some reason.

@disintegrator
Copy link
Contributor Author

@disintegrator
Copy link
Contributor Author

I'm guessing this line is the culprit: https://github.com/pinojs/pino/blob/v4.17.3/pino.js#L149

data += ',"type":"Error","stack":' + this.stringify(obj.stack)

might have to change to:

data += ',"type":"Error"'
data += obj.stack ? ',"stack":' + this.stringify(obj.stack) : ''

If that's the case then I'm happy to submit a PR

@mcollina
Copy link
Member

mcollina commented Jul 20, 2018 via email

@davidmarkclements
Copy link
Member

pino-integration has picked up that this broke a test in pino-pretty

image

image

@github-actions
Copy link

github-actions bot commented Feb 9, 2022

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 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants