Skip to content

Commit

Permalink
lib: handle one of args case in ERR_MISSING_ARGS
Browse files Browse the repository at this point in the history
This makes ERR_MISSING_ARGS handle nested arrays in argument names as
one-of case and will print them as '"arg1" or "arg2" or "arg3"'.

Example:
```js
throw new ERR_MISSING_ARGS(['a', 'b', 'c']);
// will result in message:
// The "a" or "b" or "c" argument must be specified
```
  • Loading branch information
lundibundi committed Jun 23, 2020
1 parent f6dbba8 commit 12115eb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,10 @@ E('ERR_MISSING_ARGS',
assert(args.length > 0, 'At least one arg needs to be specified');
let msg = 'The ';
const len = args.length;
args = args.map((a) => `"${a}"`);
const wrap = (a) => `"${a}"`;
args = args.map(
(a) => (ArrayIsArray(a) ? a.map(wrap).join(' or ') : wrap(a))
);
switch (len) {
case 1:
msg += `${args[0]} argument`;
Expand Down

0 comments on commit 12115eb

Please sign in to comment.