« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things')
-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`);
   };
 }