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

Error serializer only works on sub err object #895

Closed
YouriT opened this issue Aug 16, 2020 · 6 comments · Fixed by #896
Closed

Error serializer only works on sub err object #895

YouriT opened this issue Aug 16, 2020 · 6 comments · Fixed by #896

Comments

@YouriT
Copy link

YouriT commented Aug 16, 2020

I'm unsure to understand why the err serializer option only works with an err key and not with all passed errors.

I would expect logger.info(ReferenceError('test')) to also use the optional serializer passed to pino just like logger.info({ err: ReferenceError('test') }) does.

Hence I would expect this test to pass:

const stream = sink()
const parent = pino({
  serializers: {
    err: (e) => ({
      t: e.constructor.name,
      m: e.message,
      s: e.stack
    })
  }
}, stream)

parent.info(ReferenceError('test'))
const o = await once(stream, 'data')
is(typeof o, 'object')
is(o.t, 'ReferenceError')
is(o.m, 'test')
is(typeof o.s, 'string')

But unfortunately it doesn't. Seem that it still uses the default error serializer rather than the custom one.

Altering the default serializer doesn't help either.

const stream = sink()
pino.stdSerializers.err = (e) => ({
  t: e.constructor.name,
  m: e.message,
  s: e.stack
})
const parent = pino({}, stream)

parent.info(ReferenceError('test'))
const o = await once(stream, 'data')
is(typeof o, 'object')
is(o.t, 'ReferenceError')
is(o.m, 'test')
is(typeof o.s, 'string')
@jsumners
Copy link
Member

Because object inspection is expensive. We merely look for keys that have been configured to have serializers before attempting to apply any serializers. You are welcome to use the logMethod hook to alter this behavior if you like.

@YouriT
Copy link
Author

YouriT commented Aug 17, 2020

That makes sense but what doesn't make sense is to be able to define a serializer that actually only works on nested key. It makes the behaviour non consistent.

What I was trying to achieve was solely to rename the stack key to exception in order to cover this case and I though I could achieve it with the err serializer but this behaviour prevents it.

@mcollina
Copy link
Member

@YouriT #896 should solve this.

@YouriT
Copy link
Author

YouriT commented Aug 17, 2020

@mcollina sure it does, many thanks! I was just trying to better illustrate what I meant when opening the issue

@Fdawgs
Copy link
Member

Fdawgs commented May 29, 2023

Closed by #896

@Fdawgs Fdawgs closed this as completed May 29, 2023
@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 Jun 29, 2023
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.

4 participants