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
```

PR-URL: #34022
Fixes: #33930
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
  • Loading branch information
lundibundi authored and Trott committed Jun 24, 2020
1 parent 7816e5f commit b546a2b
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 b546a2b

Please sign in to comment.