diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index e3c7a2cb5b36f8..4a48dd4a0864e7 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -44,7 +44,6 @@ const { isStackOverflowError, codes: { ERR_CONSOLE_WRITABLE_STREAM, - ERR_INVALID_ARG_VALUE, ERR_INCOMPATIBLE_OPTION_PAIR, }, } = require('internal/errors'); @@ -52,6 +51,7 @@ const { validateArray, validateInteger, validateObject, + validateOneOf, } = require('internal/validators'); const { previewEntries } = internalBinding('util'); const { Buffer: { isBuffer } } = require('buffer'); @@ -135,8 +135,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', 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' } );