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

[Winston 2.x] Decycle circular Error instances #1307

Merged
merged 4 commits into from
May 11, 2018
Merged

Conversation

jamesseanwright
Copy link

Hey there!

I understand that work on Winston 2 has ceased, so we can continue to use our own fork if this isn't worth pursuing for you. That said, it would be better for us to depend upon an official version of 2.x if possible.

We use Winston 2 on a legacy project at News UK and were encountering TypeError: Converting circular structure to JSON when logging cycling Error instances. It turns out that, in HEAD of 2.x:

This PR fixes both of those behaviours. I have also added a test to the helpers to assert that Errors are decycled correctly across transports, and the existing ones still pass. Nonetheless, please let me know if this behaviour impacts legacy functionality or is nonetheless undesirable for any other reason.

Thanks!

@@ -85,7 +85,7 @@ exports.clone = function (obj) {
copy[key] = obj[key];
});

return copy;
return cycle.decycle(copy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we're decycling in the base case on line 97 anyway, this is probably fine and wouldn't degrade performance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base case would never be invoked because this return is a short circuit.

package.json Outdated
@@ -1,7 +1,7 @@
{
"name": "winston",
"description": "A multi-transport async logging library for Node.js",
"version": "2.4.2",
"version": "2.5.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will manage the versions manually so no need to bump here : )

@DABH
Copy link
Contributor

DABH commented May 9, 2018

I took a quick look through this and it seems pretty reasonable. Will try to discuss briefly with @indexzero and see if we can get this merged in.

@jamesseanwright
Copy link
Author

Thanks for your quick response @DABH!

Copy link
Member

@indexzero indexzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell @rudids to give you a bonus for this ;)

@indexzero indexzero merged commit 292c2be into winstonjs:2.x May 11, 2018
@jamesseanwright
Copy link
Author

Haha! Thank you @indexzero!

@jamesseanwright
Copy link
Author

jamesseanwright commented May 31, 2018

@indexzero @DABH Do you know when this may be released? It isn't super-urgent but it would be good to move away from our fork as soon as the latest 2.x changes are published. Cheers!

@DABH
Copy link
Contributor

DABH commented Jun 5, 2018

We’re trying to push out the 3.0 release this week, so we will plan to push a 2.x maintenance release concurrently or right after 3.0 is pushed!

@jamesseanwright
Copy link
Author

Awesome, I'll keep an eye out for it. Thanks for the pointer! 😊

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.

3 participants