From 25a8a5f1c0145c88401da8930aace1feedee0cf1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 23 Jun 2023 18:22:13 -0300 Subject: infra: log content function spec errors more cleanly --- src/content/dependencies/index.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/content/dependencies/index.js') 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); } } -- cgit 1.3.0-6-gf8a5