Preserve plugin host error codes

This commit is contained in:
Dotta committed 2026-05-22 13:17:11 +00:00
1 parent 0ad2413ff8
commit a99078e282
2 files changed
+11 -1

No files matched your search

@@ -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 {
+9 -1
View File
@@ -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,
),
);