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

console,util: revert #23162 #29592

Closed
wants to merge 3 commits into from
Closed

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Sep 17, 2019

Edit by @Fishrock123: issue description at #29592 (comment)


This reverts #23162 so that util.format() works as before.

Both TSC members (@addaleax and @jasnell) who gave their LG to the original PR seem to be in favor of reverting to the old behavior. I therefore went ahead and opened this PR.

I requested the review of all people being involved in #29539 to take a look at this.

Refs: #29539

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Sep 17, 2019
@jasnell
Copy link
Member

jasnell commented Sep 17, 2019

To be certain, I'm +1 on reverting in 12.x, I think there's still a discussion to be had about whether this should be reverted in master. Either way, the original should have been considered semver-major Scratch that, getting my issues mixed up lol ... this was originally semver-major :-) ... looking back over the history, yeah, this should be reverted

@silverwind
Copy link
Contributor

I will not approve this. To me, the old behaviour was broken and inconsistent. Thought should be given if the revert itself is a semver-major given that 12.0.0 released five months ago with this change.

jasnell
jasnell previously approved these changes Sep 17, 2019
doc/api/util.md Outdated Show resolved Hide resolved
@jasnell
Copy link
Member

jasnell commented Sep 17, 2019

I think considering this revert a semver-major may be appropriate

@silverwind
Copy link
Contributor

Either way, the original should have been considered semver-major

You seem rather ignorant here based on the fact that this was all done orderly in a semver-major and released in 12.0.0. Your statement is just plain wrong.

@sam-github sam-github added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 17, 2019
@jasnell
Copy link
Member

jasnell commented Sep 17, 2019

You seem rather ignorant here based on the fact that this was all done orderly in a semver-major and released in 12.0.0. Your statement is just plain wrong.

Excuse me, but that's rather rude. Please see my corrected comment.

@sam-github
Copy link
Contributor

@silverwind, please be more patient. This issue is confusing, and not helped by having a mixture of incomplete and incorrect comments in the related discussions.

I did some digging, this is my understanding of what happened.

If the first argument is a string, its is treated as a format string, and any specifiers in it may consume some number of values which are formatted as specified. This is obviously as-expected.

The surprise is how string values that are not consumed by the format string are treated. They can be unconsumed for two reasons:

  1. The first argument wasn't a string. Since it isn't a string, it doesn't have format specifiers, and consumes no values.
  2. The first argument was a string, but there are more values than are consumed by the format specifiers.

How unconsumed arg were formatted used to depend on whether the first parameter was a string:

core/build (master $% u=) % nvm use 8; node -e "console.log(Symbol('not fmt'), 'unconsumed')"; node -e "console.log('fmt %s', 5, 'unconsumed')"
Now using node v8.16.1 (npm v6.4.1)
Symbol(not fmt) 'unconsumed'
fmt 5 unconsumed
core/build (master $% u=) % nvm use 10; node -e "console.log(Symbol('not fmt'), 'unconsumed')"; node -e "console.log('fmt %s', 5, 'unconsumed')"
Now using node v10.16.3 (npm v6.9.0)
Symbol(not fmt) 'unconsumed'
fmt 5 unconsumed
core/build (master $% u=) % nvm use 12; node -e "console.log(Symbol('not fmt'), 'unconsumed')"; node -e "console.log('fmt %s', 5, 'unconsumed')"
Now using node v12.10.0 (npm v6.10.3)
Symbol(not fmt) unconsumed
fmt 5 unconsumed

#23162 removed this inconsistency in how unconsumed string arguments were treated in 12.x, making them be treated uniformly in the two cases, by not inspecting them.

12 is also more consistent wrt. how unconsumed non-string values are treated (I'm not sure if this was because of #23162). 12 seems to convert to a string (String(unconsumed)) only when explicitly requested with a '%s' format, whereas 10 would do it based on whether the first arg was a format string or not:

core/build (master $% u=) % nvm use 10; node -e "console.log(console.log)"; node -e "console.log(Symbol('sym'), console.log)"; node -e "console.log('fmt %s', console.log)"; node -e "console.log('unconsumed', console.log)";
Now using node v10.16.3 (npm v6.9.0)
[Function: bound consoleCall]
Symbol(sym) [Function: bound consoleCall]
fmt function () { [native code] }
unconsumed function () { [native code] }

core/build (master $% u=) % nvm use 12; node -e "console.log(console.log)"; node -e "console.log(Symbol('sym'), console.log)"; node -e "console.log('fmt %s', console.log)"; node -e "console.log('unconsumed', console.log)";
Now using node v12.10.0 (npm v6.10.3)
[Function: bound consoleCall]
Symbol(sym) [Function: bound consoleCall]
fmt function () { [native code] }
unconsumed [Function: bound consoleCall]

I'm guessing that people using console.log() for debugging are expecting to see more "inspect"-like output (strings quoted), whereas people using console.log() for CLI output want to see more direct string printing (no added quotes). #23162 kept things the same for this second use case:

core/build (master $% u=) % nvm i 10; node -e "console.log('hello', 'my', 'friend')"
v10.16.3 is already installed.
Now using node v10.16.3 (npm v6.9.0)
hello my friend
core/build (master $% u=) % nvm i 12; node -e "console.log('hello', 'my', 'friend')"
v12.10.0 is already installed.
Now using node v12.10.0 (npm v6.10.3)
hello my friend

Summary: I think there are only three options for the next major release line

  1. Unconsumed args are treated differently depending on whether a format string didn't consume them, or there was no format string to consume them (10.x and before does this)
  2. Uniformly inspect them (no release line does this)
  3. Uniformly print the (uninspected) value of the string (12.x does this)

doc/api/util.md Outdated Show resolved Hide resolved
doc/api/util.md Show resolved Hide resolved
@BridgeAR
Copy link
Member Author

Rebased due to conflicts. PTAL

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 23, 2019
@Trott
Copy link
Member

Trott commented Sep 24, 2019

I interpret @silverwind's initial comment as blocking opposition to this, so I'm going to remove the author ready label.

@silverwind: If I'm wrong and you're OK with this (just perhaps not willing to approve it yourself) then please comment to that effect. Thanks!

@Trott Trott removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 24, 2019
@BridgeAR
Copy link
Member Author

@refack PTAL since you also approved the original PR.

@BridgeAR
Copy link
Member Author

@nodejs/tsc PTAL

@BridgeAR BridgeAR added the review wanted PRs that need reviews. label Sep 26, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Trott commented Oct 4, 2019

Adding tsc-agenda because it seems like a TSC vote will be required to decide whether this should land and be in the 13.0.0 release (over @silverwind's objection) or whether 13.0.0 should go out with the existing behavior.

@nodejs/tsc In the hopes of getting a quick resolution (since the release will happen in less than 3 weeks), please leave a reaction here. I think the four options cover all the likely possibilities, but if not, leave a comment!

🎉 = revert (land this)
❤️ = do not revert (close this without landing)
👀 = abstaining
😞 = I don't know what my vote is yet, will have a better idea after TSC talks about it

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@Trott Trott added the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label Oct 10, 2019
@Fishrock123
Copy link
Contributor

Fishrock123 commented Oct 10, 2019

FWIW Web browsers disagree on this behavior entirely.

  • Chrome: acts like our old behavior
  • Firefox: acts like our new behavior
  • Safari: acts completely differently
    • Symbol(not fmt) – "unconsumed"
    • fmt 5 – "unconsumed"
  • Edge: internal error on inspecting a Symbol, otherwise like our new behavior

I think the new behavior is more consistent. If it should be changed, I think the unconsumed case where a formatter is present should still inspect (like Safari). I suspect that would not be widely liked though, and so I think the present v12 behavior of non-quoting strings is better, if different.

ALSO: This was intentionally changed in a major 5 months ago which will be LTS. Reverting this in the following major seems like a mistake to me. I would suggest reverting in 12 but I bet the ship's sailed on that.

Edit, that being said, one might expect the following to work, although it does not:

console.log('fmt %s', 5, 'fmt2 %s', 6)

@Fishrock123
Copy link
Contributor

Fishrock123 commented Oct 10, 2019

Additionally, this issue is not particularly clear, so here is an explanation. The issue is what should happen to the second (string) argument in e.g. console.log(Symbol('not fmt'), 'unconsumed').

The old behavior ran it through util.inspect, where as the new prints the string directly:

Symbol(not fmt) 'unconsumed' // old
Symbol(not fmt) unconsumed   // new

Note that when this happens with a formatter, it always directly prints the string (with or without the change):

> console.log('fmt %s', 5, 'unconsumed')
fmt 5 unconsumed

@targos
Copy link
Member

targos commented Oct 11, 2019

Thanks for the explanation @Fishrock123.
I think we should keep the current behavior. It is more consistent and predictable than the previous one.

This reduces the information and sorts the entries.
This reverts nodejs#23162. The gained
consistency did not outweight the benefit of inspecting the arguments.
Therefore it is best to revert to the former behavior.

Refs: nodejs#29539
Refs: nodejs#23162
@Trott
Copy link
Member

Trott commented Oct 14, 2019

(Rebased and force-pushed to resolve a pair of conflicts in the docs. Just formatting/lint stuff.)

@apapirovski
Copy link
Member

apapirovski commented Oct 14, 2019

Reverting this makes sense to me. Reverting as a semver-major, given that 12 is an LTS line, doesn’t. I think more of this discussion needs to cover that point.

@Fishrock123 Fishrock123 self-requested a review October 14, 2019 19:14
@jasnell jasnell dismissed their stale review October 16, 2019 15:31

I'm really torn on this. Going to remove my approval on the change

@sam-github
Copy link
Contributor

After discussion, I'm at:

  • The current 12.x behaviour is more consistent
  • It breaks with 11.x (as our policy allows), and while I'm not sure the break was worth it, its too late now to change this in 12.x, without an extraordinary break of our process (we'd have to land a semver major in 12.x just before it goes LTS, in violation of our policy)
  • Changing it back for 13.x just means 10.x would be one way, 12.x would be a different way, and 13.x/14.x would go back to 10.x's way.... but even if we are concerned that the 12.x change was unncessary, flipflopping back and forth doesn't seem helpful to anybody.

So, I'm arriving at do not land for this -- lets keep 12.x's behaviour now and forever.

@Trott
Copy link
Member

Trott commented Oct 16, 2019

Consensus at the TSC meeting is to not revert. This can remain open if @BridgeAR or anyone else wants to continue to make the case, but this won't land in 13.0.0. It will likely have to land in 14.0.0 if at all.

@Trott Trott removed the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label Oct 16, 2019
@Trott Trott removed this from the 13.0.0 milestone Oct 16, 2019
@BridgeAR BridgeAR closed this Jan 20, 2020
@BridgeAR BridgeAR deleted the revert-23162 branch January 20, 2020 12:05
@BridgeAR BridgeAR restored the revert-23162 branch January 20, 2020 12:06
@BridgeAR BridgeAR reopened this Jan 20, 2020
@BridgeAR BridgeAR force-pushed the master branch 2 times, most recently from 8ae28ff to 2935f72 Compare May 31, 2020 12:19
@jasnell
Copy link
Member

jasnell commented Jun 19, 2020

Ping @BridgeAR ... what do you want to do with this one?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Jun 25, 2020
@jasnell
Copy link
Member

jasnell commented Jul 7, 2020

Closing due to lack of continued activity on this one. Can reopen if it needs to be revisited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review wanted PRs that need reviews. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs that are stalled. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.