« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content-function.js19
-rw-r--r--src/write/build-modes/live-dev-server.js10
2 files changed, 24 insertions, 5 deletions
diff --git a/src/content-function.js b/src/content-function.js
index 921b5bcd..ede5bb74 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 =
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index 10b40cf0..3d29a83f 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -33,6 +33,7 @@ import {
   flattenRelationsTree,
   getRelationsTree,
   getNeededContentDependencyNames,
+  sourceAnnotation,
 } from '../../content-function.js';
 
 const defaultHost = '0.0.0.0';
@@ -429,11 +430,16 @@ export async function go({
 
       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 =