Skip to content

Commit be55f3e

Browse files
BridgeARcodebytere
authored andcommitted
tty: do not end in an infinite warning recursion
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>
1 parent 58f17c0 commit be55f3e

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

lib/internal/tty.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,26 @@ const TERM_ENVS_REG_EXP = [
7373
/^vt100/
7474
];
7575

76+
let warned = false;
7677
function warnOnDeactivatedColors(env) {
77-
let name;
78+
if (warned)
79+
return;
80+
let name = '';
7881
if (env.NODE_DISABLE_COLORS !== undefined)
7982
name = 'NODE_DISABLE_COLORS';
80-
if (env.NO_COLOR !== undefined)
81-
name = 'NO_COLOR';
83+
if (env.NO_COLOR !== undefined) {
84+
if (name !== '') {
85+
name += "' and '";
86+
}
87+
name += 'NO_COLOR';
88+
}
8289

83-
if (name !== undefined) {
90+
if (name !== '') {
8491
process.emitWarning(
8592
`The '${name}' env is ignored due to the 'FORCE_COLOR' env being set.`,
8693
'Warning'
8794
);
95+
warned = true;
8896
}
8997
}
9098

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
process.env.NODE_DISABLE_COLORS = '1';
6+
process.env.FORCE_COLOR = '3';
7+
8+
console.log();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
process.env.NO_COLOR = '1';
6+
process.env.NODE_DISABLE_COLORS = '1';
7+
process.env.FORCE_COLOR = '3';
8+
9+
console.log();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
11
(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
2-
(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
3-
(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
4-
(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
5-
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
6-
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
7-
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
8-
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.

0 commit comments

Comments
 (0)