-
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
assert,tty: fix indicator and warning #31429
Closed
BridgeAR
wants to merge
6
commits into
nodejs:master
from
BridgeAR:2020-01-20-assert-tty-fix-indicator-and-warning
Closed
assert,tty: fix indicator and warning #31429
BridgeAR
wants to merge
6
commits into
nodejs:master
from
BridgeAR:2020-01-20-assert-tty-fix-indicator-and-warning
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This makes sure color codes are not taken into account in case util.inspect's default value was changed.
Make sure the assertion is actually triggered by using `assert.throws()` instead of `try/catch`.
It was possible that this warning ends up in an infinite recursion. The reason is that printing the warning triggered a color check and that triggered another warning. Limiting it to a single warning prevents this.
nodejs-github-bot
added
assert
Issues and PRs related to the assert subsystem.
tty
Issues and PRs related to the tty subsystem.
labels
Jan 20, 2020
richardlau
reviewed
Jan 20, 2020
Trott
reviewed
Jan 22, 2020
jasnell
approved these changes
Jan 23, 2020
This could use another review. @nodejs/assert @nodejs/testing @nodejs/tty PTAL |
Trott
approved these changes
Feb 9, 2020
addaleax
approved these changes
Feb 9, 2020
Landed in 1450ea7...63f10b9 🎉 |
BridgeAR
added a commit
to BridgeAR/node
that referenced
this pull request
Feb 9, 2020
This makes sure color codes are not taken into account in case util.inspect's default value was changed. PR-URL: nodejs#31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
BridgeAR
added a commit
to BridgeAR/node
that referenced
this pull request
Feb 9, 2020
Make sure the assertion is actually triggered by using `assert.throws()` instead of `try/catch`. PR-URL: nodejs#31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
BridgeAR
added a commit
to BridgeAR/node
that referenced
this pull request
Feb 9, 2020
It was possible that this warning ends up in an infinite recursion. The reason is that printing the warning triggered a color check and that triggered another warning. Limiting it to a single warning prevents this. PR-URL: nodejs#31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Feb 17, 2020
This makes sure color codes are not taken into account in case util.inspect's default value was changed. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Feb 17, 2020
Make sure the assertion is actually triggered by using `assert.throws()` instead of `try/catch`. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Feb 17, 2020
It was possible that this warning ends up in an infinite recursion. The reason is that printing the warning triggered a color check and that triggered another warning. Limiting it to a single warning prevents this. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Merged
@BridgeAR How do you feel about tweaking it a bit for sake of readability? I guess it is slightly less performant but if you are fine with tradeoff I can do a quick PR with proposed changes. diff --git a/lib/internal/tty.js b/lib/internal/tty.js
index 44d5173700..3e0da04890 100644
--- a/lib/internal/tty.js
+++ b/lib/internal/tty.js
@@ -26,6 +26,7 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE
} = require('internal/errors').codes;
+const { Boolean } = primordials;
let OSRelease;
@@ -77,23 +78,21 @@ let warned = false;
function warnOnDeactivatedColors(env) {
if (warned)
return;
- let name = '';
- if (env.NODE_DISABLE_COLORS !== undefined)
- name = 'NODE_DISABLE_COLORS';
- if (env.NO_COLOR !== undefined) {
- if (name !== '') {
- name += "' and '";
- }
- name += 'NO_COLOR';
- }
- if (name !== '') {
- process.emitWarning(
- `The '${name}' env is ignored due to the 'FORCE_COLOR' env being set.`,
- 'Warning'
- );
- warned = true;
- }
+ const name = [
+ env.NODE_DISABLE_COLORS !== undefined && '\'NODE_DISABLE_COLORS\'',
+ env.NO_COLOR !== undefined && '\'NO_COLOR\''
+ ].filter(Boolean).join(' and ');
+
+ if (!name)
+ return;
+
+ process.emitWarning(
+ `The ${name} env variable is ignored due to the 'FORCE_COLOR' env ` +
+ 'variable being set.',
+ 'Warning'
+ );
+ warned = true;
}
// The `getColorDepth` API got inspired by multiple sources such as
|
codebytere
pushed a commit
that referenced
this pull request
Mar 15, 2020
This makes sure color codes are not taken into account in case util.inspect's default value was changed. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Mar 15, 2020
Make sure the assertion is actually triggered by using `assert.throws()` instead of `try/catch`. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Mar 15, 2020
It was possible that this warning ends up in an infinite recursion. The reason is that printing the warning triggered a color check and that triggered another warning. Limiting it to a single warning prevents this. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Mar 17, 2020
This makes sure color codes are not taken into account in case util.inspect's default value was changed. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Mar 17, 2020
Make sure the assertion is actually triggered by using `assert.throws()` instead of `try/catch`. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Mar 17, 2020
It was possible that this warning ends up in an infinite recursion. The reason is that printing the warning triggered a color check and that triggered another warning. Limiting it to a single warning prevents this. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Merged
codebytere
pushed a commit
that referenced
this pull request
Mar 30, 2020
This makes sure color codes are not taken into account in case util.inspect's default value was changed. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Mar 30, 2020
Make sure the assertion is actually triggered by using `assert.throws()` instead of `try/catch`. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere
pushed a commit
that referenced
this pull request
Mar 30, 2020
It was possible that this warning ends up in an infinite recursion. The reason is that printing the warning triggered a color check and that triggered another warning. Limiting it to a single warning prevents this. PR-URL: #31429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please have a look at the commit messages. I can split this into two PRs but I stumbled upon both things at the same time and they seemed small enough that individual commits might suffice.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes