From b546a2b469da113b9edb43b61c8e4d854c6f7432 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Mon, 22 Jun 2020 19:49:21 +0300 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/34022 Fixes: https://github.com/nodejs/node/issues/33930 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Zeyu Yang --- lib/internal/errors.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index e7563515f6ee4b..936888c0e29b38 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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`;