mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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>
This commit is contained in:
parent
8a8ca4b0bf
commit
c66e6471e7
63 changed files with 315 additions and 325 deletions
|
@ -53,7 +53,7 @@ const kInspect = require('internal/util').customInspectSymbol;
|
|||
const {
|
||||
ERR_INVALID_CALLBACK,
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_OPT_VALUE,
|
||||
ERR_INVALID_ARG_VALUE,
|
||||
ERR_VALID_PERFORMANCE_ENTRY_TYPE,
|
||||
ERR_INVALID_PERFORMANCE_MARK
|
||||
} = require('internal/errors').codes;
|
||||
|
@ -348,7 +348,7 @@ class PerformanceObserver extends AsyncResource {
|
|||
}
|
||||
const { entryTypes } = options;
|
||||
if (!ArrayIsArray(entryTypes)) {
|
||||
throw new ERR_INVALID_OPT_VALUE('entryTypes', entryTypes);
|
||||
throw new ERR_INVALID_ARG_VALUE('options.entryTypes', entryTypes);
|
||||
}
|
||||
const filteredEntryTypes = entryTypes.filter(filterTypes).map(mapTypes);
|
||||
if (filteredEntryTypes.length === 0) {
|
||||
|
@ -608,7 +608,7 @@ function monitorEventLoopDelay(options = {}) {
|
|||
'number', resolution);
|
||||
}
|
||||
if (resolution <= 0 || !NumberIsSafeInteger(resolution)) {
|
||||
throw new ERR_INVALID_OPT_VALUE.RangeError('resolution', resolution);
|
||||
throw new ERR_INVALID_ARG_VALUE.RangeError('resolution', resolution);
|
||||
}
|
||||
return new ELDHistogram(new _ELDHistogram(resolution));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue