From 24d16ef9b1692779e40b7a461fc2d39156a8a1d1 Mon Sep 17 00:00:00 2001 From: olzzon Date: Thu, 28 Aug 2025 11:47:32 +0200 Subject: [PATCH 1/3] fix: BP evaluation add process and return error if failing runInContext --- meteor/server/api/blueprints/cache.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/meteor/server/api/blueprints/cache.ts b/meteor/server/api/blueprints/cache.ts index e2d542494c..3d3f4abfb1 100644 --- a/meteor/server/api/blueprints/cache.ts +++ b/meteor/server/api/blueprints/cache.ts @@ -6,7 +6,7 @@ import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyE export function evalBlueprint(blueprint: Pick): SomeBlueprintManifest { const blueprintPath = `db:///blueprint/${blueprint.name || blueprint._id}-bundle.js` - const context = vm.createContext({}, {}) + const context = vm.createContext({ process: process }, {}) const script = new vm.Script( `__run_result = ${blueprint.code} __run_result || blueprint`, @@ -14,7 +14,13 @@ __run_result || blueprint`, filename: blueprintPath, } ) - const entry = script.runInContext(context) + + let entry: any + try { + entry = script.runInContext(context) + } catch (e) { + console.error(`Error evaluating Blueprint .runInContext "${blueprint._id}": "${stringifyError(e)}"`) + } const manifest: SomeBlueprintManifest = entry.default From 32e86032f1d8a49a962512b137463534b0587c42 Mon Sep 17 00:00:00 2001 From: olzzon Date: Thu, 28 Aug 2025 11:52:07 +0200 Subject: [PATCH 2/3] fix: BP evaluation undo add process --- meteor/server/api/blueprints/cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/server/api/blueprints/cache.ts b/meteor/server/api/blueprints/cache.ts index 3d3f4abfb1..f15eab329e 100644 --- a/meteor/server/api/blueprints/cache.ts +++ b/meteor/server/api/blueprints/cache.ts @@ -6,7 +6,7 @@ import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyE export function evalBlueprint(blueprint: Pick): SomeBlueprintManifest { const blueprintPath = `db:///blueprint/${blueprint.name || blueprint._id}-bundle.js` - const context = vm.createContext({ process: process }, {}) + const context = vm.createContext({}, {}) const script = new vm.Script( `__run_result = ${blueprint.code} __run_result || blueprint`, From aad268971667f2de42b08f29a04b444d5a82da49 Mon Sep 17 00:00:00 2001 From: olzzon Date: Thu, 28 Aug 2025 12:12:00 +0200 Subject: [PATCH 3/3] fix: use logger instead of console --- meteor/server/api/blueprints/cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/server/api/blueprints/cache.ts b/meteor/server/api/blueprints/cache.ts index f15eab329e..1eecf3c523 100644 --- a/meteor/server/api/blueprints/cache.ts +++ b/meteor/server/api/blueprints/cache.ts @@ -19,7 +19,7 @@ __run_result || blueprint`, try { entry = script.runInContext(context) } catch (e) { - console.error(`Error evaluating Blueprint .runInContext "${blueprint._id}": "${stringifyError(e)}"`) + logger.error(`Error evaluating Blueprint .runInContext "${blueprint._id}": "${stringifyError(e)}"`) } const manifest: SomeBlueprintManifest = entry.default