« get me outta code hell

infra: annotate errors with name outside fulfillDependencies - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-11 11:42:06 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-11 11:42:56 -0300
commit4eba3396a31ffb13151d5603f2ba9473ef3d7a8c (patch)
treecea484629b8e0986bba3fc3d0604fb32faf2e412 /src
parent61d41ae57ec745b75ff9bc0568a2c6b9873acb89 (diff)
infra: annotate errors with name outside fulfillDependencies
Diffstat (limited to 'src')
-rw-r--r--src/content-function.js30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/content-function.js b/src/content-function.js
index c86d55a8..ab9977f2 100644
--- a/src/content-function.js
+++ b/src/content-function.js
@@ -108,7 +108,7 @@ export function expectDependencies({
     wrappedGenerate.fulfilled = true;
 
     wrappedGenerate.fulfill = function() {
-      throw new Error(`All dependencies already fulfilled`);
+      throw new Error(`All dependencies already fulfilled (${generate.name})`);
     };
   }
 
@@ -127,6 +127,21 @@ export function expectDependencies({
   }
 
   wrappedGenerate.fulfill ??= function fulfill(dependencies) {
+    let newlyFulfilledDependencies;
+
+    try {
+      newlyFulfilledDependencies =
+        fulfillDependencies({
+          dependencies,
+          expectedContentDependencyKeys,
+          expectedExtraDependencyKeys,
+          fulfilledDependencies,
+        });
+    } catch (error) {
+      error.message += ` (${generate.name})`;
+      throw error;
+    }
+
     return expectDependencies({
       sprawl,
       relations,
@@ -136,15 +151,9 @@ export function expectDependencies({
       expectedContentDependencyKeys,
       expectedExtraDependencyKeys,
 
-      fulfilledDependencies: fulfillDependencies({
-        name: generate.name,
-        dependencies,
-
-        expectedContentDependencyKeys,
-        expectedExtraDependencyKeys,
-        fulfilledDependencies,
-      }),
+      fulfilledDependencies: newlyFulfilledDependencies,
     });
+
   };
 
   Object.assign(wrappedGenerate, {
@@ -156,7 +165,6 @@ export function expectDependencies({
 }
 
 export function fulfillDependencies({
-  name,
   dependencies,
   expectedContentDependencyKeys,
   expectedExtraDependencyKeys,
@@ -208,7 +216,7 @@ export function fulfillDependencies({
   }
 
   if (!empty(errors)) {
-    throw new AggregateError(errors, `Errors fulfilling dependencies for ${name}`);
+    throw new AggregateError(errors, `Errors fulfilling dependencies`);
   }
 
   return newFulfilledDependencies;