Skip to content

Commit 084a23f

Browse files
author
Benjamin E. Coe
authored
refactor!: switch to existing ERR_INVALID_ARG_VALUE (#97)
1 parent 4903e5e commit 084a23f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

errors.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ class ERR_INVALID_ARG_TYPE extends TypeError {
77
}
88
}
99

10-
class ERR_INVALID_SHORT_OPTION extends TypeError {
11-
constructor(longOption, shortOption) {
12-
super(`options.${longOption}.short must be a single character, got '${shortOption}'`);
13-
this.code = 'ERR_INVALID_SHORT_OPTION';
10+
class ERR_INVALID_ARG_VALUE extends TypeError {
11+
constructor(arg1, arg2, expected) {
12+
super(`The property ${arg1} ${expected}. Received '${arg2}'`);
13+
this.code = 'ERR_INVALID_ARG_VALUE';
1414
}
1515
}
1616

1717
module.exports = {
1818
codes: {
1919
ERR_INVALID_ARG_TYPE,
20-
ERR_INVALID_SHORT_OPTION
20+
ERR_INVALID_ARG_VALUE
2121
}
2222
};

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434

3535
const {
3636
codes: {
37-
ERR_INVALID_SHORT_OPTION,
37+
ERR_INVALID_ARG_VALUE,
3838
},
3939
} = require('./errors');
4040

@@ -117,7 +117,11 @@ const parseArgs = ({
117117
const shortOption = optionConfig.short;
118118
validateString(shortOption, `options.${longOption}.short`);
119119
if (shortOption.length !== 1) {
120-
throw new ERR_INVALID_SHORT_OPTION(longOption, shortOption);
120+
throw new ERR_INVALID_ARG_VALUE(
121+
`options.${longOption}.short`,
122+
shortOption,
123+
'must be a single character'
124+
);
121125
}
122126
}
123127

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ test('invalid short option length', (t) => {
412412
const passedOptions = { foo: { short: 'fo', type: 'boolean' } };
413413

414414
t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, {
415-
code: 'ERR_INVALID_SHORT_OPTION'
415+
code: 'ERR_INVALID_ARG_VALUE'
416416
});
417417

418418
t.end();

0 commit comments

Comments
 (0)