diff --git a/server/src/__tests__/plugin-worker-manager.test.ts b/server/src/__tests__/plugin-worker-manager.test.ts index adb61c43315..93bc92c7612 100644 --- a/server/src/__tests__/plugin-worker-manager.test.ts +++ b/server/src/__tests__/plugin-worker-manager.test.ts @@ -6,6 +6,7 @@ import { createHostClientHandlers, type HostServices, JsonRpcCallError, + PLUGIN_RPC_ERROR_CODES, type HostToWorkerMethods, } from "@paperclipai/plugin-sdk"; import { @@ -274,6 +275,7 @@ describe("plugin-worker-manager stderr failure context", () => { }, renderEnvironment: null, })).rejects.toMatchObject({ + code: PLUGIN_RPC_ERROR_CODES.INVOCATION_SCOPE_DENIED, message: expect.stringContaining("scoped to company \"company-a\""), }); } finally { diff --git a/server/src/services/plugin-worker-manager.ts b/server/src/services/plugin-worker-manager.ts index a67dc80d96f..f2094e073d5 100644 --- a/server/src/services/plugin-worker-manager.ts +++ b/server/src/services/plugin-worker-manager.ts @@ -469,6 +469,14 @@ export function createPluginWorkerHandle( return undefined; } + function errorCodeForWorkerHostError(err: unknown): number { + const code = (err as { code?: unknown } | null)?.code; + const pluginErrorCodes: readonly number[] = Object.values(PLUGIN_RPC_ERROR_CODES); + return typeof code === "number" && pluginErrorCodes.includes(code) + ? code + : JSONRPC_ERROR_CODES.INTERNAL_ERROR; + } + // ----------------------------------------------------------------------- // Incoming message handling // ----------------------------------------------------------------------- @@ -559,7 +567,7 @@ export function createPluginWorkerHandle( sendMessage( createErrorResponse( request.id, - JSONRPC_ERROR_CODES.INTERNAL_ERROR, + errorCodeForWorkerHostError(err), errorMessage, ), );