« get me outta code hell

composite: chain and collate errors from compositional steps - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-02 22:16:07 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-02 22:16:07 -0300
commit93ec3d5b62bc16cb9f18962a5b8c4e4a7576280f (patch)
tree8ed733bf121b572783fd4319ca3ae0b291df85df
parent7c5caf5923a7771de16e1479539e66c7a693b186 (diff)
composite: chain and collate errors from compositional steps
-rw-r--r--src/data/composite.js34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/data/composite.js b/src/data/composite.js
index 862235bd..ea7a3480 100644
--- a/src/data/composite.js
+++ b/src/data/composite.js
@@ -1073,10 +1073,7 @@ export function compositeFrom(description) {
           reviewAccessedDependencies = () => {
             const topAggregate =
               openAggregate({
-                message:
-                  `Errors in dependencies accessed by step ${i+1}` +
-                  (step.annotation ? ` (${step.annotation})` : ``) +
-                  ` of ${compositionName}`,
+                message: `Errors in accessed dependencies`,
               });
 
             const showDependency = dependency =>
@@ -1176,12 +1173,38 @@ export function compositeFrom(description) {
             args.filter(arg => arg !== continuationSymbol);
         }
 
+        let stepError;
         try {
           return expose[name](...args);
+        } catch (error) {
+          stepError = error;
         } finally {
           stepsFirstTimeCalling[i] = false;
+
+          let reviewError;
           if (reviewAccessedDependencies) {
-            reviewAccessedDependencies();
+            try {
+              reviewAccessedDependencies();
+            } catch (error) {
+              reviewError = error;
+            }
+          }
+
+          const stepPart =
+            `step ${i+1}` +
+            (isBase
+              ? ` (base)`
+              : ` of ${steps.length}`) +
+            (step.annotation ? `, ${step.annotation}` : ``);
+
+          if (stepError && reviewError) {
+            throw new AggregateError(
+              [stepError, reviewError],
+              `Errors in ${stepPart}`);
+          } else if (stepError || reviewError) {
+            throw new Error(
+              `Error in ${stepPart}`,
+              {cause: stepError || reviewError});
           }
         }
       };
@@ -1360,6 +1383,7 @@ export function compositeFrom(description) {
           `Error computing composition` +
           (annotation ? ` ${annotation}` : ''));
         error.cause = thrownError;
+        error[Symbol.for('hsmusic.aggregate.translucent')] = true;
         throw error;
       }
     };