Skip to content

Commit a110409

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 <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>
1 parent 6e7de37 commit a110409

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

‎lib/internal/console/constructor.js‎

Lines changed: 2 additions & 3 deletions
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
thrownewERR_CONSOLE_WRITABLE_STREAM('stderr');
136136
}
137137

138-
if(typeofcolorMode!=='boolean'&&colorMode!=='auto')
139-
thrownewERR_INVALID_ARG_VALUE('colorMode',colorMode);
138+
validateOneOf(colorMode,'colorMode',['auto',true,false]);
140139

141140
if(groupIndentation!==undefined){
142141
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)