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

Avoid deprecation warnings in node.js 10 because we have methods called inspect #577

Merged
merged 5 commits into from
Jan 15, 2019

Conversation

papandreou
Copy link
Member

@papandreou papandreou commented Jan 11, 2019

nodejs/node#15549 🙄

In node.js 10+ the custom inspection function for our promises works, but causes a deprecation warning to be logged:

node_10_promise_inspect

Ditto for Unexpected#inspect:

node_10_expect_inspect

The fix is to provide the custom inspection function via a symbol exported as require('util').inspect.custom instead. But because we're also using the inspect method name for other things in Unexpected, we're forced to provide the symbol method on all objects that have an inspect method. This PR fixes that up so we provide both in node versions where the custom symbol exists.

@papandreou papandreou self-assigned this Jan 11, 2019
@papandreou papandreou added the WIP label Jan 11, 2019
@alexjeffburke
Copy link
Member

alexjeffburke commented Jan 12, 2019

Nice that we get rid of a deprecation warning but what we've had to do just seems.. 😬

Just to understand, we're not allowed to have an .inspect() method without registering it with the node runtime?

@papandreou
Copy link
Member Author

Just to understand, we're not allowed to have an .inspect() method without registering it with the node runtime?

Yeah, pretty much. If we have a method anywhere called inspect, node.js 10+ will print that deprecation warning unless the same object also has a method with a name of require('util').inspect.custom.

It seems our only alternative is to rename our own inspect to something else. That would be breaking and it would be really annoying to have to do that because of a poor deprecation strategy in node.js. I have no idea why they chose to do it like this, it's really disruptive.

Copy link
Member

@alexjeffburke alexjeffburke left a comment

Choose a reason for hiding this comment

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

Better that we don't show the deprecation warning of course, but I wish we didn't have to do this. As discussed with @papandreou, it's good this is being cleaned up in node land but outputting a deprecation warning affects all places where it meant something else.

@sunesimonsen
Copy link
Member

sunesimonsen commented Jan 13, 2019

Would it be an option to not call inspect on objects? I this this behavior was introduced from the very first prototype of inspection in Unexpected. Maybe things have improved 😊

@sunesimonsen
Copy link
Member

Sorry about closing the PR. That happens too often on the phone.

@papandreou
Copy link
Member Author

Would it be an option to not call inspect on objects?

Sorry, I don't understand the suggestion? It's the node repl (and require('util').inspect) that calls inspect on objects, not us.

@papandreou
Copy link
Member Author

@sunesimonsen, I'll interpret your silence as an approval ;)

@papandreou papandreou merged commit 86aabfd into master Jan 15, 2019
@papandreou papandreou deleted the fix/node10inspect branch January 15, 2019 22:23
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