-
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
console.error unexpectedly turns output red #53661
Comments
FWIW I'm +1 on the idea of making the coloring of console opt-in, but that's not my say. (Or just removing it entirely, and having the users handle it themselves) CC @nodejs/console |
I'm +1 on making the colorization opt-in |
I'm -1 on making colorization opt-in. Color has been opt-out in the runtime for as long as I can remember and I would need a much stronger argument to be convinced otherwise. Although I don't necessarily agree with the current state of things, the |
-1 as well. maybe we can find another mitigation. |
Shouldn't the color only be default when the stdout/stderr are TTY? I wonder #53665 is more of a bug of the TTY detection not smart enough |
+1 on making the color opt-in, expect tty maybe |
I remember testing TTY detection and it was working as expected. |
From what I can tell, the TTY detection is working as expected. |
Docs or not, I do think |
FWIW The way I see it, there are few different choices here, such as:
|
What major versions implement the updated colorization? As a compromise here, I'd suggest that we make sure the change is not backported to anything before 22 if it has been already and we retroactively mark it a semver-major change. Keep the new behavior moving forward with the additional documentation, |
FWIW, I think two different things are getting mixed up.
#40361 seems to have been the motivating factor for the change. If you ignore the title and read the body of the request, it was asking to colorize the
My vote:
#51629 was a great POC, it has established that some people want color added and others do not. Even so, I do not believe it is the right long term approach on how to add color to |
FWIW there is already an option to opt-out from coloring when stderr is tty: |
It'll opt-out all types of coloring which might have added intentionally by the user and not just console.warn/error right? So people who only want to opt-out from default coloring of warn/error and keep other coloring can't use it |
that is correct, but why is there an essential difference? |
It is a huge difference. When I use But, in the current implementation of From my perspective, #51629 landed without any formal review of the impact or a design discussion on how to give the best experience. What problem was #51629 solving? It didn't solve #40361, that user was asking for more control over the output of errors. It does not work for that: Example code: const error = new Error('This is an error message');
console.error(error);
console.error('This is an error: ', error);
console.error('Just some text.'); Here is what #40361 was talking about: code: import util from 'node:util';
const error = new Error('This is an error message');
console.error(error);
console.log('We want the Error Title to be Red:');
console.error(util.styleText('red', util.format(error))); I can empathize with #40361, it is impossible to nicely change the format of the Error message. Why should we keep #51629 when what it does could be easily implemented in user land: console.error(util.styleText('red', 'My message.')); |
I wonder if packages that get broken are intercepting stderr output by monkey patching process.stderr, which is still expected to work in TTY; in that case it seems the colorization should also check whether the process.stderr has been monkey patched. |
What are the next steps to take? Should I make a PR that rolls back that change? So far, I see no benefit in keeping #51629. |
I'm not sure, some of the collaborators in this issue may know |
- added import sorting, proper namespace import resolution - added formatting options for imports and op id decorator - on dry run, create files in virtual project and support outputting the changes to the terminal - added support for configuring default service content - patched console coloured output nodejs/node#53661 - added dts and source map to dev build (stripped in dist files) - bump codegen parser dep
I've opened a revert #54677. WDYT? |
Related to PR #51629
I'm a bit surprised that this landed without a link to the discussion. #40361 is a feature request, but doesn't have a real discussion around the pros/cons and how it will impact the nodejs ecosystem.
I would have rather seen color added to the formatting of Errors instead of blanket red/yellow for console.error/console.warn.
I realize that in some way, this PR makes the behavior closer to that in the browser, but browsers do not have CLI applications.
I treat console.log and console.error as separate channels. Traditionally
stdout
is used for output of the program. It contains the result to be used, thinkgrep
.stderr
is used for diagnostics, status, and messages to the user while the application is running. Color is not implied.I would rather that this PR implemented color as a opt in vs trying to figure out how to opt out.
Originally posted by @Jason3S in #51629 (comment)
The text was updated successfully, but these errors were encountered: