« get me outta code hell

infra: log content function spec errors more cleanly - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-23 18:22:13 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-23 18:22:13 -0300
commit25a8a5f1c0145c88401da8930aace1feedee0cf1 (patch)
tree7793a6c8ab66508d806d329579d87e1453075c0b /src/content/dependencies
parent53395fa815cdf6f912e78f80bef8908005186270 (diff)
infra: log content function spec errors more cleanly
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/index.js18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/content/dependencies/index.js b/src/content/dependencies/index.js
index e78bc94b..f7a0a659 100644
--- a/src/content/dependencies/index.js
+++ b/src/content/dependencies/index.js
@@ -6,7 +6,7 @@ import {readdir} from 'node:fs/promises';
 import * as path from 'node:path';
 import {fileURLToPath} from 'node:url';
 
-import contentFunction from '../../content-function.js';
+import contentFunction, {ContentFunctionSpecError} from '../../content-function.js';
 import {color, logWarn} from '../../util/cli.js';
 import {annotateFunction} from '../../util/sugar.js';
 
@@ -205,6 +205,8 @@ export function watchContentDependencies({
 
       if (typeof error === 'string') {
         console.error(color.yellow(error));
+      } else if (error instanceof ContentFunctionSpecError) {
+        console.error(color.yellow(error.message));
       } else {
         console.error(error);
       }
@@ -214,23 +216,15 @@ export function watchContentDependencies({
   }
 
   function processFunctionSpec(functionName, spec) {
-    if (typeof spec.data === 'function') {
+    if (typeof spec?.data === 'function') {
       annotateFunction(spec.data, {name: functionName, description: 'data'});
     }
 
-    if (typeof spec.generate === 'function') {
+    if (typeof spec?.generate === 'function') {
       annotateFunction(spec.generate, {name: functionName});
     }
 
-    let fn;
-    try {
-      fn = contentFunction(spec);
-    } catch (error) {
-      error.message = `Error loading spec: ${error.message}`;
-      throw error;
-    }
-
-    return fn;
+    return contentFunction(spec);
   }
 }