From 553ffeb4fc0d25685a566d7771f6c0f13308baa5 Mon Sep 17 00:00:00 2001 From: rayark1 Date: Wed, 7 Aug 2024 21:00:13 +0900 Subject: [PATCH 1/2] console: use validateOneOf for colorMode validation refactor the Console constructor to use validateOneOf for validating the colorMode parameter. --- lib/internal/console/constructor.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 6c34a9ededcc60..c892b91919da75 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -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', From 621df44f4d9e246879f71507fe88ee7e8419332f Mon Sep 17 00:00:00 2001 From: rayark1 Date: Wed, 7 Aug 2024 21:41:04 +0900 Subject: [PATCH 2/2] test: update expected error messages in test-console-tty-colors.js --- test/parallel/test-console-tty-colors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-console-tty-colors.js b/test/parallel/test-console-tty-colors.js index 0eb51c72898f7c..69951e27e3c6b0 100644 --- a/test/parallel/test-console-tty-colors.js +++ b/test/parallel/test-console-tty-colors.js @@ -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' } );