Uh oh!
There was an error while loading. Please reload this page.
util: deprecate obj.inspect for custom inspection - #15631
Conversation
There was a problem hiding this comment.
not sure, but maybe "equivalent but deprecated"?
There was a problem hiding this comment.
Yes, you're correct. Even better might be or the equivalent but deprecated which is what I'll switch it to in a minute.
addaleax
commented
Sep 26, 2017
Just to give context, the alternative was only introduced a little more than a year ago in 6.4.0. I am perfectly fine with landing this in 8.x but I’d like to wait a little longer until we consider a runtime-deprecation. |
Trott
commented
Sep 27, 2017
Labeling |
evanlucas
commented
Sep 27, 2017
can we check ecosystem usage of this before we land this? |
Trott
commented
Sep 28, 2017
@evanlucas The same question was asked in #15549 and @refack answered (in #15549 (comment)) like this:
|
querying for |
ljharb
commented
Sep 29, 2017
Can someone confirm; will |
jasnell
commented
Sep 29, 2017
Yes, the string inspect will still work. This is a docs only deprecation for now. Which means no runtime changes at all |
There was a problem hiding this comment.
It might be helpful to note that, if compatibility is desired, having the method present under both names is always going to work?
There was a problem hiding this comment.
I like the idea but I'm struggling with how to word it in a way that doesn't encourage people to use both if they're only using the Symbol. We don't want to create more messages if/when we move to a runtime deprecation. Suggestions welcome.
There was a problem hiding this comment.
@Trott The thing is, even if we move to a runtime deprecation, the symbol property will be the first one that’s detected, and the string property ignored – so if both are present, the runtime deprecation won’t be emitted… or am I misunderstanding what you’re saying?
There was a problem hiding this comment.
@addaleax Good point. I've added some text in a separate commit.
refack
commented
Sep 29, 2017
AFAICT the long term "plan" is to runtime deprecate then remove, but that cycle requires at least two major versions, and future consensus. |
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
| function for [`util.inspect()`][] is deprecated. Use [`util.inspect.custom`][] | ||
| instead. | ||
| instead. (For backwards compatibility with Node.js prior to version 6.4.0, both | ||
| may be specified.) |
There was a problem hiding this comment.
instead (For backwards compatibility with Node.js prior to version 6.4.0, both may be specified). ?
There was a problem hiding this comment.
I think since it's a whole sentence (not just a clause) inside the parentheses the period should be inside.
http://www.thepunctuationguide.com/parentheses.html
There was a problem hiding this comment.
Perhaps the parentheses are unnecessary anyway?
BridgeAR
commented
Oct 2, 2017
Landed in c09c04f I removed the braces while landing. |
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>
MylesBorins
commented
Oct 3, 2017
This does not land cleanly on 8.x. Could you please manually backport. |
MylesBorins
commented
Oct 3, 2017
nvm I figured it out |
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>
Notable Changes: * deps: * update npm to 5.4.2 #15600 * upgrade libuv to 1.15.0 #15745 * update V8 to 6.1.534.42 #15393 * dgram: * support for setting dgram socket buffer size #13623 * fs: * add support O_DSYNC file open constant #15451 * util: * deprecate obj.inspect for custom inspection #15631 * tools, build: * there is a fancy new macOS installer #15179 * Added new collaborator * bmeurer - Benedikt Meurer - https://github.com/bmeurer * kfarnung - Kyle Farnung - https://github.com/kfarnung PR-URL: #15762
Notable Changes: * deps: * update npm to 5.4.2 #15600 * upgrade libuv to 1.15.0 #15745 * update V8 to 6.1.534.42 #15393 * dgram: * support for setting dgram socket buffer size #13623 * fs: * add support O_DSYNC file open constant #15451 * util: * deprecate obj.inspect for custom inspection #15631 * tools, build: * there is a fancy new macOS installer #15179 * Added new collaborator * bmeurer - Benedikt Meurer - https://github.com/bmeurer * kfarnung - Kyle Farnung - https://github.com/kfarnung PR-URL: #15762
Notable Changes: * deps: * update npm to 5.4.2 nodejs/node#15600 * upgrade libuv to 1.15.0 nodejs/node#15745 * update V8 to 6.1.534.42 nodejs/node#15393 * dgram: * support for setting dgram socket buffer size nodejs/node#13623 * fs: * add support O_DSYNC file open constant nodejs/node#15451 * util: * deprecate obj.inspect for custom inspection nodejs/node#15631 * tools, build: * there is a fancy new macOS installer nodejs/node#15179 * Added new collaborator * bmeurer - Benedikt Meurer - https://github.com/bmeurer * kfarnung - Kyle Farnung - https://github.com/kfarnung PR-URL: nodejs/node#15762
I saw the change, read documentation and played with the Node and the code, and still cannot quite get it... In order to provide custom console output for each of my custom types I used to do this: MyType.prototype.inspect=function(){return'CUSTOM VALUE';}How am I to change this code for the latest Node.js? |
addaleax
commented
Oct 17, 2017
@vitaly-t basically, whenever you want your custom inspect function and care about older Node versions, also do: MyType.prototype.inspect=function(){return'CUSTOM VALUE';};if(util.inspect.custom){MyType.prototype[util.inspect.custom]=MyType.prototype.inspect;}If you do not care about Node < 6.4.0, you can (and probably should) just use MyType.prototype[util.inspect.custom]=function(){return'CUSTOM VALUE';};The reason for this is that it’s hard to tell for Node whether |
@addaleax Thank you! But if this is the case, then why the first code below works fine, while the one after doesn't? Works: constobj={inspect: ()=>{return'INSPECT';}};console.log(obj);//=> INSPECTDoesn't work: constobj={util: {inspect: {custom: ()=>{return'INSPECT';}}}};console.log(obj);//=> { util: { inspect: { custom: [Function: custom] }}}Node.js v8.7.0 |
@vitaly-t it's constobj={[require('util').inspect.custom](){return'INSPECT';}};console.log(obj); |
@ljharb Ouch,... tricky! I think documentation needs to get better on this one 😄 Thank you! Also, I'd like to figure out what that |
addaleax
commented
Oct 18, 2017
PRs are definitely very welcome!
I am not sure if this is helpful or not, but: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol (i.e. there isn’t really much more information contained in the value of |
gibfahn
commented
Jan 15, 2018
Release team were -1 on landing on v6.x, if you disagree let us know. |
ljharb
commented
Jan 15, 2018
@gibfahn on landing the deprecation, the new symbol, or either? |
gibfahn
commented
Jan 15, 2018
On landing the deprecation, though it wasn't a heavy -1, as with all backports we'd like to hear others' thoughts (we have a week to decide). Which is the new symbol? I don't see it in this PR. |
The existence of
obj.inspect()for custom inspection can cause peopleto unintentionally break
console.log()and friends. This is adocumentation-only deprecation that can hopefully land in 8.x.
Refs: #15549
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
util