« get me outta code hell

validators: validateAllPropertyValues: don't use withAggregate - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
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
commit897918a65f452922b9ea99be20fb1a14daf9c264 (patch)
tree091068575b6100532bc49c121230068a7031cd95 /src/data
parent649ed77f4df1cc0fff4354ce0f91e961cfab21d1 (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.js33
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`);
   };
 }