diff options
author | Denys Otrishko <shishugi@gmail.com> | 2020-08-08 19:01:59 +0300 |
---|---|---|
committer | Denys Otrishko <shishugi@gmail.com> | 2020-09-11 17:54:42 +0300 |
commit | c66e6471e780e752f3f6f9337ac49a3d6e3d7091 (patch) | |
tree | 524ef0656926ccabeef54a170c5a3cb9e3f4b289 /lib/internal/dns | |
parent | 8a8ca4b0bf123c708130a1152e960a9310c2ccc4 (diff) |
lib: remove ERR_INVALID_OPT_VALUE and ERR_INVALID_OPT_VALUE_ENCODING
This will be a start to generalize all argument validation
errors. As currently we throw ARG/OPT, OUT_OF_RANGE, and other more
specific errors.
The OPT errors didn't bring much to the errors as it's just another
variant of ARG error which is sometimes more confusing (some of our code
used OPT errors to denote just argument validation errors presumably
because of similarity of OPT to 'option' and not 'options-object')
and they don't specify the name of the options object where the invalid
value is located. Much better approach would be to just specify path
to the invalid value in the name of the value as it is done in this PR
(i.e. 'options.format', 'options.publicKey.type' etc)
Also since this decreases a variety of errors we have it'd be easier to
reuse validation code across the codebase.
Refs: https://github.com/nodejs/node/pull/31251
Refs: https://github.com/nodejs/node/pull/34070#discussion_r467251009
Signed-off-by: Denys Otrishko <shishugi@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/34682
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/internal/dns')
-rw-r--r-- | lib/internal/dns/promises.js | 6 | ||||
-rw-r--r-- | lib/internal/dns/utils.js | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 19ad6e5bfb3..2b76613509a 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -26,7 +26,7 @@ const { } = internalBinding('cares_wrap'); const { ERR_INVALID_ARG_TYPE, - ERR_INVALID_OPT_VALUE, + ERR_INVALID_ARG_VALUE, ERR_MISSING_ARGS, } = codes; const { @@ -154,7 +154,7 @@ function lookupService(address, port) { throw new ERR_MISSING_ARGS('address', 'port'); if (isIP(address) === 0) - throw new ERR_INVALID_OPT_VALUE('address', address); + throw new ERR_INVALID_ARG_VALUE('address', address); validatePort(port); @@ -236,7 +236,7 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) { resolver = resolveMap[rrtype]; if (typeof resolver !== 'function') - throw new ERR_INVALID_OPT_VALUE('rrtype', rrtype); + throw new ERR_INVALID_ARG_VALUE('rrtype', rrtype); } else if (rrtype === undefined) { resolver = resolveMap.A; } else { diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index 6642a4f090b..9948330adcd 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -20,8 +20,8 @@ const addrSplitRE = /(^.+?)(?::(\d+))?$/; const { ERR_DNS_SET_SERVERS_FAILED, ERR_INVALID_ARG_TYPE, + ERR_INVALID_ARG_VALUE, ERR_INVALID_IP_ADDRESS, - ERR_INVALID_OPT_VALUE } = errors.codes; function validateTimeout(options) { @@ -146,7 +146,7 @@ function bindDefaultResolver(target, source) { function validateHints(hints) { if ((hints & ~(AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED)) !== 0) { - throw new ERR_INVALID_OPT_VALUE('hints', hints); + throw new ERR_INVALID_ARG_VALUE('hints', hints); } } |