Skip to content

Commit a110409

Browse files
rayark1targos
authored andcommittedOct 2, 2024
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 <kohei.ueno119@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed
 

Diff for: ‎lib/internal/console/constructor.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ const {
4444
isStackOverflowError,
4545
codes: {
4646
ERR_CONSOLE_WRITABLE_STREAM,
47-
ERR_INVALID_ARG_VALUE,
4847
ERR_INCOMPATIBLE_OPTION_PAIR,
4948
},
5049
} = require('internal/errors');
5150
const {
5251
validateArray,
5352
validateInteger,
5453
validateObject,
54+
validateOneOf,
5555
} = require('internal/validators');
5656
const { previewEntries } = internalBinding('util');
5757
const { Buffer: { isBuffer } } = require('buffer');
@@ -135,8 +135,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
135135
throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');
136136
}
137137

138-
if (typeof colorMode !== 'boolean' && colorMode !== 'auto')
139-
throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);
138+
validateOneOf(colorMode, 'colorMode', ['auto', true, false]);
140139

141140
if (groupIndentation !== undefined) {
142141
validateInteger(groupIndentation, 'groupIndentation',

Diff for: ‎test/parallel/test-console-tty-colors.js

+1-1
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)
Please sign in to comment.