« get me outta code hell

infra: hook content function generate() into new trace algorithm - 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-12-30 09:52:17 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-30 13:07:03 -0400
commit9302a8b165f67e8de44300cfda8aa26287e9609a (patch)
treeeadf9baae509e4ec384fb9384023d62762e2384e /src
parent6f1642dd0f1fc79b05b98fb892d6258cfffc7e15 (diff)
infra: hook content function generate() into new trace algorithm
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;
       }
     };