From ebbe2b86d949d95368795c4e4f56758e2ce851df Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Sun, 30 Mar 2025 14:50:52 +0530 Subject: [PATCH] handle errors during policy instantiation --- packages/ditto/workers/policy.worker.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/ditto/workers/policy.worker.ts b/packages/ditto/workers/policy.worker.ts index b75f3748..72590205 100644 --- a/packages/ditto/workers/policy.worker.ts +++ b/packages/ditto/workers/policy.worker.ts @@ -8,6 +8,7 @@ import * as Comlink from 'comlink'; import { ReadOnlySigner } from '@/signers/ReadOnlySigner.ts'; import { DittoPgStore } from '@/storages/DittoPgStore.ts'; import { DEFAULT_POLICY_SPEC, PolicySpec } from '@/utils/policies.ts'; +import { logi } from '@soapbox/logi'; // @ts-ignore Don't try to access the env from this worker. Deno.env = new Map(); @@ -75,7 +76,16 @@ export class CustomPolicy implements NPolicy { for (const item of spec.policies) { const policy = registry.available[item.name]; if (!policy) continue; - policies.push(policy.instantiate(item.params || {})); + try { + policies.push(policy.instantiate(item.params || {})); + } + catch (e) { + logi({ + level: 'error', + ns: 'ditto.system.policy.worker', + msg: `Error instantiating policy ${item.name} with params \`${JSON.stringify(item.params)}\`: ${e}` + }) + } } this.policy = new PipePolicy(policies);