-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Comments
/cc @nodejs/tsc |
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. |
It's a tricky query to run... preliminary results indicate "no very often".
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. |
Found an interesting example - > 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. |
Is that done using |
|
I agree that it should be moved to a Symbol (if it has not been already), but not that it should be removed entirely. |
@Fishrock123 Yeah, there’s |
@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. |
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. |
@kriskowal the |
@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. |
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
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 <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <vsemozhetbyt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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. |
Move the use of custom inspection function to End-of-Life. Ref: nodejs#15549
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. |
Thanks @Trott. Will definitely check this. |
This removes the deprecated custom inspection function and fixes all tests accordingly. Refs: nodejs#15549
@Yomguithereal I had the same problem and solved it with inspect-custom-symbol, which uses the Still, I wish this had been implemented as e.g. |
Thanks @chocolateboy. I guess for now this is the only decent workaround :( |
I've proposed a fix for this here. |
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 <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
https://nodejs.org/api/util.html#util_custom_inspection_functions_on_objects
The use of
obj.inspect
as part of inspecting (and thereforeconsole.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
?The text was updated successfully, but these errors were encountered: