Skip to content

Commit e71390e

Browse files
rayark1targos
authored andcommitted
console: use validateOneOf for colorMode validation
refactor the Console constructor to use validateOneOf for validating the colorMode parameter. PR-URL: #54245 Reviewed-By: Kohei Ueno <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 851bcbb commit e71390e

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

lib/internal/console/constructor.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ const {
3939
codes: {
4040
ERR_CONSOLE_WRITABLE_STREAM,
4141
ERR_INCOMPATIBLE_OPTION_PAIR,
42-
ERR_INVALID_ARG_VALUE,
4342
},
4443
isStackOverflowError,
4544
} = require('internal/errors');
4645
const {
4746
validateArray,
4847
validateInteger,
4948
validateObject,
49+
validateOneOf,
5050
} = require('internal/validators');
5151
const { previewEntries } = internalBinding('util');
5252
const { Buffer: { isBuffer } } = require('buffer');
@@ -124,8 +124,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
124124
throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');
125125
}
126126

127-
if (typeof colorMode !== 'boolean' && colorMode !== 'auto')
128-
throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);
127+
validateOneOf(colorMode, 'colorMode', ['auto', true, false]);
129128

130129
if (groupIndentation !== undefined) {
131130
validateInteger(groupIndentation, 'groupIndentation',

test/parallel/test-console-tty-colors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ check(false, false, false);
6767
});
6868
},
6969
{
70-
message: `The argument 'colorMode' is invalid. Received ${received}`,
70+
message: `The argument 'colorMode' must be one of: 'auto', true, false. Received ${received}`,
7171
code: 'ERR_INVALID_ARG_VALUE'
7272
}
7373
);

0 commit comments

Comments
 (0)