« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content-function.js32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/content-function.js b/src/content-function.js
index a3d7b585..f57b606a 100644
--- a/src/content-function.js
+++ b/src/content-function.js
@@ -124,12 +124,32 @@ export function expectDependencies({
         throw new Error(`Expected relations`);
       }
 
-      if (hasDataFunction && hasRelationsFunction) {
-        return generate(arg1, arg2, ...extraArgs, fulfilledDependencies);
-      } else if (hasDataFunction || hasRelationsFunction) {
-        return generate(arg1, ...extraArgs, fulfilledDependencies);
-      } else {
-        return generate(...extraArgs, fulfilledDependencies);
+      try {
+        if (hasDataFunction && hasRelationsFunction) {
+          return generate(arg1, arg2, ...extraArgs, fulfilledDependencies);
+        } else if (hasDataFunction || hasRelationsFunction) {
+          return generate(arg1, ...extraArgs, fulfilledDependencies);
+        } else {
+          return generate(...extraArgs, fulfilledDependencies);
+        }
+      } catch (caughtError) {
+        const error = new Error(
+          `Error generating content for ${generate.name}`,
+          {cause: caughtError});
+
+        error[Symbol.for(`hsmusic.aggregate.alwaysTrace`)] = true;
+        error[Symbol.for(`hsmusic.aggregate.traceFrom`)] = caughtError;
+
+        error[Symbol.for(`hsmusic.aggregate.unhelpfulTraceLines`)] = [
+          /content-function\.js/,
+          /util\/html\.js/,
+        ];
+
+        error[Symbol.for(`hsmusic.aggregate.helpfulTraceLines`)] = [
+          /content\/dependencies\/(.*\.js:.*(?=\)))/,
+        ];
+
+        throw error;
       }
     };