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.group and console.groupCollapsed should write to stderr #55511

Open
kriskowal opened this issue Oct 24, 2024 · 6 comments
Open

console.group and console.groupCollapsed should write to stderr #55511

kriskowal opened this issue Oct 24, 2024 · 6 comments
Labels
console Issues and PRs related to the console subsystem. wontfix Issues that will not be fixed.

Comments

@kriskowal
Copy link
Contributor

Version

all

Platform

all

Subsystem

console

What steps will reproduce the bug?

Given the program console-group.js

console.group('group');
console.groupCollapsed('group collapsed');

run

node console-group.js 2>/dev/null

How often does it reproduce? Is there a required condition?

consistently, all versions

What is the expected behavior? Why is that the expected behavior?

The above command should produce no output. This prevents a diagnostic from inadvertently interleaving text in parsable stdout.

One could argue the same should apply to console.log and console.info and that all machine readable program output should be written to process.stdout explicitly, but that ship has sailed.

What do you see instead?

Send group labels to stderr.

Additional information

No response

@RedYetiDev
Copy link
Member

This is not a bug. console.group and similar commands log to stdout, not stderr.

@RedYetiDev RedYetiDev added the wontfix Issues that will not be fixed. label Oct 24, 2024
@kriskowal
Copy link
Contributor Author

I agree that console.group and console.groupCollapsed write to stdout. Is that behavior defensible on any other grounds beyond Hyrum’s Law?

@RedYetiDev
Copy link
Member

The spec leaves it up to the implementers to decide these things (https://console.spec.whatwg.org/#group), but it makes sense for it to go to stdout. It's not logging an error, so why go to stderr?

Hyrum's law is always in effect, and this behavior is compatible with all the major runtimes, so changing it (which IMO isn't necessary at all) wouldn't be an easy task

@RedYetiDev RedYetiDev added the console Issues and PRs related to the console subsystem. label Oct 24, 2024
@kriskowal
Copy link
Contributor Author

Your position is grounded on the assumption that console is an API for generating output as opposed to generating diagnostic information for a debugger, which I will grant is one valid interpretation. This is made explicit by the early design choice to borrow console for console.log("Hello, World!") and conflating the purpose of console for both debugging and generating output, in addition to direct manipulation of process.stdout and the omission of print.

So, to use the console object purely as an instrument of debugging, with the expectation that it will compose well with other portions of the program that write to stdout and also be portable to the web where console is purely an instrument for debugging, one must currently create a console adapter that detects whether the underlying platform is Node.js or the web, and shunt the whole console API through console.error. I would argue we can do better.

We do have the option of importing console and making one that does shunt to stderr, but importing console is not web portable.

@RedYetiDev
Copy link
Member

CC @nodejs/console

@kriskowal
Copy link
Contributor Author

To Hyrum’s Law, a program will break assuming that the output of group or groupCollapsed is expected to be interleaved with two-space indented log and warn and machine-readable on stdout, in Node.js, and not merely a human-readable interleaving of stdout and stderr. I believe it’s worth testing the hypothesis that this is a possible and worthwhile change. Provided that folks here come to agree and align on a design, I can propose the necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem. wontfix Issues that will not be fixed.
Projects
None yet
Development

No branches or pull requests

2 participants