diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-12-30 17:00:18 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-12-30 17:00:18 -0400 |
commit | 897918a65f452922b9ea99be20fb1a14daf9c264 (patch) | |
tree | 091068575b6100532bc49c121230068a7031cd95 /src/data | |
parent | 649ed77f4df1cc0fff4354ce0f91e961cfab21d1 (diff) |
validators: validateAllPropertyValues: don't use withAggregate
This is mostly stylistic (ala oneOf), it doesn't seem to do much for performance.
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/things/validators.js | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/data/things/validators.js b/src/data/things/validators.js index 7289b6d7..f240c6ba 100644 --- a/src/data/things/validators.js +++ b/src/data/things/validators.js @@ -395,23 +395,26 @@ export function validateAllPropertyValues(validator) { if (Array.isArray(object)) throw new TypeError(`Expected an object, got array`); - withAggregate({message: `Errors validating object properties`}, ({call}) => { - for (const key of Reflect.ownKeys(object)) { - call(() => { - const value = object[key]; - try { - validator(value); - } catch (error) { - const keyPart = colors.green(key.toString()); - const valuePart = inspect(value); - error.message = `(key: ${keyPart}, value: ${valuePart}) ${error.message}`; - throw error; - } - }); + const errors = []; + + for (const key of Reflect.ownKeys(object)) { + const value = object[key]; + try { + validator(value); + } catch (error) { + const keyPart = colors.green(key.toString()); + const valuePart = inspect(value); + error.message = `(key: ${keyPart}, value: ${valuePart}) ${error.message}`; + errors.push(error); } - }); + } - return true; + if (empty(errors)) { + return true; + } + + throw new AggregateError(errors, + `Errors validating object properties`); }; } |