From 897918a65f452922b9ea99be20fb1a14daf9c264 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 30 Dec 2023 17:00:18 -0400 Subject: validators: validateAllPropertyValues: don't use withAggregate This is mostly stylistic (ala oneOf), it doesn't seem to do much for performance. --- src/data/things/validators.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src/data/things') 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`); }; } -- cgit 1.3.0-6-gf8a5