console: use validateOneOf for colorMode validation

refactor the Console constructor to use validateOneOf for validating
the colorMode parameter.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
HEESEUNG 2024-08-10 10:49:40 +09:00 committed by GitHub
parent 4557c13c21
commit 90d91abbfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 4 deletions

View File

@ -39,7 +39,6 @@ const {
codes: {
ERR_CONSOLE_WRITABLE_STREAM,
ERR_INCOMPATIBLE_OPTION_PAIR,
ERR_INVALID_ARG_VALUE,
},
isStackOverflowError,
} = require('internal/errors');
@ -47,6 +46,7 @@ const {
validateArray,
validateInteger,
validateObject,
validateOneOf,
} = require('internal/validators');
const { previewEntries } = internalBinding('util');
const { Buffer: { isBuffer } } = require('buffer');
@ -124,8 +124,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');
}
if (typeof colorMode !== 'boolean' && colorMode !== 'auto')
throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);
validateOneOf(colorMode, 'colorMode', ['auto', true, false]);
if (groupIndentation !== undefined) {
validateInteger(groupIndentation, 'groupIndentation',

View File

@ -67,7 +67,7 @@ check(false, false, false);
});
},
{
message: `The argument 'colorMode' is invalid. Received ${received}`,
message: `The argument 'colorMode' must be one of: 'auto', true, false. Received ${received}`,
code: 'ERR_INVALID_ARG_VALUE'
}
);