From a6c7e09e2a01ef1520967d9654e7fe3f9e14b008 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Sat, 14 Mar 2026 13:51:41 -0700 Subject: [PATCH] fix(plugins): log plugin handler errors, warn on double-init Address Greptile review feedback: - Log plugin event handler errors via logger.warn instead of silently discarding the emit() result - Warn if setPluginEventBus is called more than once Co-Authored-By: Claude Opus 4.6 (1M context) --- server/src/services/activity-log.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/services/activity-log.ts b/server/src/services/activity-log.ts index 4c7248bd..16758b94 100644 --- a/server/src/services/activity-log.ts +++ b/server/src/services/activity-log.ts @@ -6,6 +6,7 @@ import type { PluginEvent } from "@paperclipai/plugin-sdk"; import { publishLiveEvent } from "./live-events.js"; import { redactCurrentUserValue } from "../log-redaction.js"; import { sanitizeRecord } from "../redaction.js"; +import { logger } from "../middleware/logger.js"; import type { PluginEventBus } from "./plugin-event-bus.js"; const PLUGIN_EVENT_SET: ReadonlySet = new Set(PLUGIN_EVENT_TYPES); @@ -14,6 +15,9 @@ let _pluginEventBus: PluginEventBus | null = null; /** Wire the plugin event bus so domain events are forwarded to plugins. */ export function setPluginEventBus(bus: PluginEventBus): void { + if (_pluginEventBus) { + logger.warn("setPluginEventBus called more than once, replacing existing bus"); + } _pluginEventBus = bus; } @@ -75,6 +79,10 @@ export async function logActivity(db: Db, input: LogActivityInput) { runId: input.runId ?? null, }, }; - void _pluginEventBus.emit(event).catch(() => {}); + void _pluginEventBus.emit(event).then(({ errors }) => { + for (const { pluginId, error } of errors) { + logger.warn({ pluginId, eventType: event.eventType, err: error }, "plugin event handler failed"); + } + }).catch(() => {}); } }