« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/util/sugar.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 26982eb6..8ed37ff8 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -329,6 +329,9 @@ export function openAggregate({
   // generally useful outside of developer debugging purposes - it will be
   // skipped by default when using showAggregate, showing contained errors
   // inline with other children of this aggregate's parent.
+  //
+  // If set to 'single', it'll be hidden only if there's a single error in the
+  // aggregate (so it's not grouping multiple errors together).
   translucent = false,
 
   // Value to return when a provided function throws an error. If this is a
@@ -416,7 +419,7 @@ export function openAggregate({
       const error = Reflect.construct(errorClass, [errors, message]);
 
       if (translucent) {
-        error[Symbol.for(`hsmusic.aggregate.translucent`)] = true;
+        error[Symbol.for('hsmusic.aggregate.translucent')] = translucent;
       }
 
       throw error;
@@ -647,6 +650,13 @@ export function showAggregate(topError, {
       return cause;
     }
 
+    if (translucency === 'single') {
+      if (cause.errors?.length === 1) {
+        return determineCauseHelper(cause.errors[0]);
+      } else {
+        return cause;
+      }
+    }
 
     return determineCauseHelper(cause.cause);
   };
@@ -663,6 +673,10 @@ export function showAggregate(topError, {
       return [error];
     }
 
+    if (translucency === 'single' && error.errors?.length >= 2) {
+      return [error];
+    }
+
     const errors = [];
 
     if (error.cause) {