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

Don't swallow Error message/stack when using formatter #1188

Conversation

evanbattaglia
Copy link

Fixes #1178

When we use a formatter and pass an Error object in as meta,
we end up removing the Error's message and stack information when
decycleing it. clone checks if the passed-in object is an Error
and does not decycle it in that case, but when we use a formatter,
this check does not happen because we clone the whole options object
instead of just cloning options.meta.

By cloneing meta alone when it is an Error,
the instanceof Error check will catch it and copy message and stack
into a new, non-Error object. So when that's buried in options.meta,
re-cloneing it won't hurt.

Fixes winstonjs#1178

When we use a formatter and pass an `Error` object in as `meta`,
we end up removing the Error's message and stack information when
`decycle`ing it. `clone` checks if the passed-in object is an `Error`
and does not `decycle` it in that case, but when we use a formatter,
this check does not happen because we `clone` the whole `options` object
instead of just cloning `options.meta`.

By `clone`ing `meta` alone when it is an Error,
the `instanceof Error` check will catch it and copy `message` and `stack`
into a new, non-Error object. So when that's buried in `options.meta`,
re-`clone`ing it won't hurt.
kewitz added a commit to invisible-tech/logger that referenced this pull request Jan 29, 2018
@julianhille
Copy link

julianhille commented Feb 21, 2018

Works for me. Tested it with a custom formatter and also tested if
winston.info('Message', new Error('ErrorMessage'))
output is close to the same to:
winston.info('Message', {anything: new Error('ErrorMessage')})

Actually i'm confused why this is still open.

@julianhille
Copy link

I'd like to see a test for it so that this won't happen again,

Add test for "Don't swallow Error message/stack when using formatter",
which Fixes winstonjs#1178
@evanbattaglia
Copy link
Author

I added a test and confirmed that it works on my branch but fails for the 2.x branch.

@marcusmotill
Copy link

shipit!

@indexzero
Copy link
Member

Thanks for your contribution. Will get a maintenance release out tomorrow.

@indexzero indexzero merged commit edfaa8b into winstonjs:2.x Apr 19, 2018
cjbarth pushed a commit to cjbarth/winston that referenced this pull request Aug 22, 2018
* commit 'dc74db60b8d46475fce04bab1e0c31abe5201e09': (34 commits)
  [dist] Maintenance release. 2.4.3
  [Winston 2.x] Decycle circular `Error` instances (winstonjs#1307)
  [dist] Maintenance release. 2.4.2
  [dist] Add .gitattributes file.
  [fix] Backport winstonjs#1281 onto 2.x for maintenance.
  [dist] Add ignores from 3.x for easier maintenance switching.
  fix: clone() cloning prototype's custom methods (winstonjs#1086)
  Don't swallow Error message/stack when using formatter (winstonjs#1188)
  [dist] Add package-lock.json
  Update http.js - Add support for headers
  fix 2.x readme (fixes winstonjs#1179)
  [dist] Maintenance release. 2.4.1
  Always pass a function to fs.close (winstonjs#1227)
  Update documentation for the `stringify` option
  [dist] Version bump. 2.4.0
  [fix] Correct documentation mistake in 2.x
  Add how to colorize output in the custom formatter example (winstonjs#989)
  [fix] Container.add() 'filters' and 'rewriters' option passing to logger (winstonjs#1036)
  Fixed working of "humanReadableUnhandledException" parameter when additional data is added in meta (winstonjs#1066)
  Added filtering by log level (winstonjs#1040)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants