diff --git a/errors.js b/errors.js index 1b9eb95..2f260d7 100644 --- a/errors.js +++ b/errors.js @@ -7,16 +7,16 @@ class ERR_INVALID_ARG_TYPE extends TypeError { } } -class ERR_INVALID_SHORT_OPTION extends TypeError { - constructor(longOption, shortOption) { - super(`options.${longOption}.short must be a single character, got '${shortOption}'`); - this.code = 'ERR_INVALID_SHORT_OPTION'; +class ERR_INVALID_ARG_VALUE extends TypeError { + constructor(arg1, arg2, expected) { + super(`The property ${arg1} ${expected}. Received '${arg2}'`); + this.code = 'ERR_INVALID_ARG_VALUE'; } } module.exports = { codes: { ERR_INVALID_ARG_TYPE, - ERR_INVALID_SHORT_OPTION + ERR_INVALID_ARG_VALUE } }; diff --git a/index.js b/index.js index 6fb591e..ac0e78f 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ const { const { codes: { - ERR_INVALID_SHORT_OPTION, + ERR_INVALID_ARG_VALUE, }, } = require('./errors'); @@ -117,7 +117,11 @@ const parseArgs = ({ const shortOption = optionConfig.short; validateString(shortOption, `options.${longOption}.short`); if (shortOption.length !== 1) { - throw new ERR_INVALID_SHORT_OPTION(longOption, shortOption); + throw new ERR_INVALID_ARG_VALUE( + `options.${longOption}.short`, + shortOption, + 'must be a single character' + ); } } diff --git a/test/index.js b/test/index.js index 93fe85c..2a8f99b 100644 --- a/test/index.js +++ b/test/index.js @@ -412,7 +412,7 @@ test('invalid short option length', (t) => { const passedOptions = { foo: { short: 'fo', type: 'boolean' } }; t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, { - code: 'ERR_INVALID_SHORT_OPTION' + code: 'ERR_INVALID_ARG_VALUE' }); t.end();