Skip to content

Commit b546a2b

Browse files
lundibundiTrott
authored andcommitted
lib: handle one of args case in ERR_MISSING_ARGS
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]>
1 parent 7816e5f commit b546a2b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/internal/errors.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,10 @@ E('ERR_MISSING_ARGS',
12531253
assert(args.length > 0, 'At least one arg needs to be specified');
12541254
let msg = 'The ';
12551255
const len = args.length;
1256-
args = args.map((a) => `"${a}"`);
1256+
const wrap = (a) => `"${a}"`;
1257+
args = args.map(
1258+
(a) => (ArrayIsArray(a) ? a.map(wrap).join(' or ') : wrap(a))
1259+
);
12571260
switch (len) {
12581261
case 1:
12591262
msg += `${args[0]} argument`;

0 commit comments

Comments
 (0)