« get me outta code hell

infra: report who sourced unfulfilled relations - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content-function.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-02 09:30:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-02 09:30:20 -0300
commite09e11f1b933fa67f07c9f5e4340466f89672c8b (patch)
tree615c9b766bff08c925f75bfc0dc33ddedcb3358c /src/content-function.js
parentd646ae0de00aebefb15faedfbdfe9995e2250b17 (diff)
infra: report who sourced unfulfilled relations
Diffstat (limited to 'src/content-function.js')
-rw-r--r--src/content-function.js19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/content-function.js b/src/content-function.js
index 921b5bc..ede5bb7 100644
--- a/src/content-function.js
+++ b/src/content-function.js
@@ -206,6 +206,8 @@ export function fulfillDependencies({
   return newFulfilledDependencies;
 }
 
+export const sourceAnnotation = Symbol('Source');
+
 export function getRelationsTree(dependencies, contentFunctionName, wikiData, ...args) {
   const relationIdentifier = Symbol('Relation');
 
@@ -234,7 +236,11 @@ export function getRelationsTree(dependencies, contentFunctionName, wikiData, ..
 
     const relationFunction = (name, ...args) => {
       const relationSymbol = Symbol(relationSymbolMessage(name));
-      relationSlots[relationSymbol] = {name, args};
+      relationSlots[relationSymbol] = {
+        name,
+        args,
+        [sourceAnnotation]: contentFunctionName,
+      };
       return {[relationIdentifier]: relationSymbol};
     };
 
@@ -252,6 +258,7 @@ export function getRelationsTree(dependencies, contentFunctionName, wikiData, ..
         ]));
 
     return {
+      [sourceAnnotation]: contentFunctionName,
       layout: relationsLayout,
       slots: relationSlots,
       tree: relationsTree,
@@ -289,6 +296,7 @@ export function flattenRelationsTree({
         name: slots[slot].name,
         args: slots[slot].args,
         relations: tree[slot]?.layout ?? null,
+        [sourceAnnotation]: slots[slot][sourceAnnotation],
       };
     }
   }
@@ -435,11 +443,16 @@ export function quickEvaluate({
 
   const slotResults = {};
 
-  function runContentFunction({name, args, relations: flatRelations}) {
+  function runContentFunction({
+    name,
+    args,
+    relations: flatRelations,
+    [sourceAnnotation]: sourceName,
+  }) {
     const contentFunction = fulfilledContentDependencies[name];
 
     if (!contentFunction) {
-      throw new Error(`Content function ${name} unfulfilled or not listed`);
+      throw new Error(`Content function ${name} unfulfilled or not listed (from ${sourceName})`);
     }
 
     const sprawl =