mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-22 00:30:19 +02:00
Preserve plugin host error codes
This commit is contained in:
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 {
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user