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

Deprecate object.inspect for custom inspection #15549

Closed
jakearchibald opened this issue Sep 22, 2017 · 23 comments
Closed

Deprecate object.inspect for custom inspection #15549

jakearchibald opened this issue Sep 22, 2017 · 23 comments
Labels
util Issues and PRs related to the built-in util module.

Comments

@jakearchibald
Copy link

https://nodejs.org/api/util.html#util_custom_inspection_functions_on_objects

The use of obj.inspect as part of inspecting (and therefore console.log) seems to catch people out https://twitter.com/wSokra/status/910070904666943489.

Given that there's a Symbol now, is there a plan to deprecate obj.inspect?

@mscdex mscdex added question Issues that look for answers. util Issues and PRs related to the built-in util module. labels Sep 22, 2017
@BridgeAR
Copy link
Member

I agree that it would be good to deprecate that. It is difficult to know how many people rely on this right now though.

@ChALkeR @refack would you be so kind and try finding out how often this might be used?

@MylesBorins
Copy link
Contributor

/cc @nodejs/tsc

@TimothyGu
Copy link
Member

I'm not TSC but I'm 👍 on this. Compatibility risks are always there, but util.inspect will still give an output for objects after this change, just a less helpful one.

@refack
Copy link
Contributor

refack commented Sep 23, 2017

@ChALkeR @refack would you be so kind and try finding out how often this might be used?

It's a tricky query to run... preliminary results indicate "no very often".

Compatibility risks are always there, but util.inspect will still give an output for objects after this change, just a less helpful one.

Just a reminder, deprecation is still far from removal (a full cycle needs at least two major versions). And even after a "full deprecation" removal is not automatic. So IMHO if it's a "bad" API that already has a better implementation, deciding to deprecate should be easier.

@refack
Copy link
Contributor

refack commented Sep 23, 2017

Found an interesting example - Q

> p = Q.Promise((r) => { r('a') })
{ state: 'fulfilled', value: 'a' }
> util.inspect.defaultOptions.customInspect = false
false
> p
{ [String: 'a']
  promiseDispatch: [Function],
  valueOf: [Function],
  inspect: [Function] }
>

It not exactly negative or positive, although IMHO it's more positive, since the inspection should show the full internal state.
/cc @kriskowal

@jakearchibald
Copy link
Author

Is that done using .inspect or the symbol? Should be easy to get Q to switch to the symbol.

@refack
Copy link
Contributor

refack commented Sep 23, 2017

Is that done using .inspect or the symbol? Should be easy to get Q to switch to the symbol.

Q promises have a semantic inspect method, so IMHO this is an example of bad interaction (pro deprecation).

@Fishrock123
Copy link
Contributor

I agree that it should be moved to a Symbol (if it has not been already), but not that it should be removed entirely.

@addaleax
Copy link
Member

@Fishrock123 Yeah, there’s util.inspect.custom for exactly that. :) Node 4.x doesn’t have it, unfortunately.

@BridgeAR
Copy link
Member

@Fishrock123 the main point is to remove this and not about using the symbol version. The reason is that you can not inspect all objects properly with this and that is a bad API. You always have to think about not inspecting anything that has a "inspect" function on it that is not meant as a custom inspect function.

@kriskowal
Copy link
Contributor

Folks do depend on inspect’s presence and shape of its return value, and while it deliberately interacts with util.inspect as-it-was for debug purposes, it seems relatively unlikely that any code depends on the interaction. We can claw back the current behavior with the symbol.

Aside, it seems to me like custom inspect methods should be receiving a Set of visited objects that they can pass back to util.inspect recursively, to break cyclic references.

@BridgeAR
Copy link
Member

BridgeAR commented Sep 25, 2017

@kriskowal the customInspect function already receives the set of visited objects. It is on the second argument the seen property.
And as you can see due to this issue being opened including the mentioned tweet, people did run into issues because of the current behavior. We do not know how many but it seems like quite a few people are not happy with the current implementation and prefer a side effect free variant like the symbol one.

@kriskowal
Copy link
Contributor

kriskowal commented Sep 25, 2017

@BridgeAR Filed under kriskowal/q#822

We’ll need to find a way to feature-detect the symbol. Q is old enough that it lives is in the realm of “you might not be using CommonJS”, and if you are using CommonJS, it doesn’t assume you’re using Node.js either. From time to time, folks remind me that they’re using Q in a script tag or with an old version of Browserify.

Trott added a commit to Trott/io.js that referenced this issue Sep 29, 2017
The existence of `obj.inspect()` for custom inspection can cause people
to unintentionally break `console.log()` and friends. This is a
documentation-only deprecation that can hopefully land in 8.x.

Refs: nodejs#15549
BridgeAR pushed a commit that referenced this issue Oct 2, 2017
The existence of `obj.inspect()` for custom inspection can cause people
to unintentionally break `console.log()` and friends. This is a
documentation-only deprecation that can hopefully land in 8.x.

PR-URL: #15631
Refs: #15549
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Oct 3, 2017
The existence of `obj.inspect()` for custom inspection can cause people
to unintentionally break `console.log()` and friends. This is a
documentation-only deprecation that can hopefully land in 8.x.

PR-URL: #15631
Refs: #15549
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Oct 3, 2017
The existence of `obj.inspect()` for custom inspection can cause people
to unintentionally break `console.log()` and friends. This is a
documentation-only deprecation that can hopefully land in 8.x.

PR-URL: #15631
Refs: #15549
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit to addaleax/ayo that referenced this issue Oct 4, 2017
The existence of `obj.inspect()` for custom inspection can cause people
to unintentionally break `console.log()` and friends. This is a
documentation-only deprecation that can hopefully land in 8.x.

PR-URL: nodejs/node#15631
Refs: nodejs/node#15549
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Oct 11, 2017
The existence of `obj.inspect()` for custom inspection can cause people
to unintentionally break `console.log()` and friends. This is a
documentation-only deprecation that can hopefully land in 8.x.

PR-URL: #15631
Refs: #15549
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@Trott
Copy link
Member

Trott commented Oct 22, 2017

Runtime deprecation proposed in #16393. We're past the deadline for this landing in 9.0.0 without extraordinary action. So if it lands, it won't be seen in a release at least until 10.0.0.

Trott added a commit to Trott/io.js that referenced this issue May 4, 2018
Move the use of custom inspection function to End-of-Life.

Ref: nodejs#15549
@Trott
Copy link
Member

Trott commented May 4, 2018

Opened a pull request with a milestone for 11.0.0 to move this to End-of-Life. If that lands and is released in 11.0.0 (which is due out in October 2018), then the API can be removed at any time after that, although we'd probably target 12.0.0 (April 2019) at the earliest for full removal.

@Yomguithereal
Copy link

Thanks @Trott. Will definitely check this.

BridgeAR added a commit to BridgeAR/node that referenced this issue May 14, 2018
This removes the deprecated custom inspection function and fixes
all tests accordingly.

Refs: nodejs#15549
@chocolateboy
Copy link
Contributor

chocolateboy commented May 18, 2018

@Yomguithereal I had the same problem and solved it with inspect-custom-symbol, which uses the browser field in its package.json to provide a (different) symbol in the browser without requiring util (and thereby forcing it to be pulled in by Browserify etc.).

Still, I wish this had been implemented as e.g. Symbol.for('util.inspect.custom') rather than a private symbol that requires this kind of workaround.

@Yomguithereal
Copy link

Thanks @chocolateboy. I guess for now this is the only decent workaround :(

@chocolateboy
Copy link
Contributor

@Yomguithereal

I guess for now this is the only decent workaround :(

I've proposed a fix for this here.

BridgeAR added a commit to BridgeAR/node that referenced this issue May 19, 2018
This removes the deprecated custom inspection function and fixes
all tests accordingly.

Refs: nodejs#15549

PR-URL: nodejs#20722
Refs: nodejs#15549
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@BridgeAR BridgeAR removed the question Issues that look for answers. label May 28, 2018
@BridgeAR
Copy link
Member

BridgeAR commented May 28, 2018

This got resolved with #16393 and #20722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests