« get me outta code hell

data: use error.cause for nested composite compute errors - 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>2023-09-21 15:53:35 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-21 15:54:11 -0300
commit8e3e15be98d43c1aa8a4f13709106f6848a0a9e4 (patch)
tree43421a0498f1004ee4a7534865ee02bf4b60f3a0
parentcb124756780e41c6791981233da4b56c031d6142 (diff)
data: use error.cause for nested composite compute errors
-rw-r--r--src/data/things/composite.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index e6cc267a..4074aef7 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -1369,15 +1369,27 @@ export function compositeFrom(description) {
         ...dependenciesFromSteps,
       ]);
 
+    const _wrapper = (...args) => {
+      try {
+        return _computeOrTransform(...args);
+      } catch (thrownError) {
+        const error = new Error(
+          `Error computing composition` +
+          (annotation ? ` ${annotation}` : ''));
+        error.cause = thrownError;
+        throw error;
+      }
+    };
+
     if (compositionNests) {
       if (compositionUpdates) {
         expose.transform = (value, continuation, dependencies) =>
-          _computeOrTransform(value, continuation, dependencies);
+          _wrapper(value, continuation, dependencies);
       }
 
       if (anyStepsCompute) {
         expose.compute = (continuation, dependencies) =>
-          _computeOrTransform(noTransformSymbol, continuation, dependencies);
+          _wrapper(noTransformSymbol, continuation, dependencies);
       }
 
       if (base.cacheComposition) {
@@ -1385,10 +1397,10 @@ export function compositeFrom(description) {
       }
     } else if (compositionUpdates) {
       expose.transform = (value, dependencies) =>
-        _computeOrTransform(value, null, dependencies);
+        _wrapper(value, null, dependencies);
     } else {
       expose.compute = (dependencies) =>
-        _computeOrTransform(noTransformSymbol, null, dependencies);
+        _wrapper(noTransformSymbol, null, dependencies);
     }
   }