diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/protocol/old.ts b/rivetkit-typescript/packages/rivetkit/src/actor/protocol/old.ts index 0854a8d2e5..c830cd86f3 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/protocol/old.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/protocol/old.ts @@ -299,20 +299,29 @@ export async function processMessage< errorData, TO_CLIENT_VERSIONED, ToClientSchema, - // JSON: metadata is the raw value - (value): ToClientJson => ({ - body: { - tag: "Error" as const, - val: { - group: value.group, - code: value.code, - message: value.message, - metadata: value.metadata ?? null, - actionId: value.actionId ?? null, + // JSON: metadata is the raw value (keep as undefined if not present) + (value): ToClientJson => { + const val: any = { + group: value.group, + code: value.code, + message: value.message, + actionId: + value.actionId !== undefined + ? value.actionId + : null, + }; + if (value.metadata !== undefined) { + val.metadata = value.metadata; + } + return { + body: { + tag: "Error" as const, + val, }, - }, - }), + }; + }, // BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer + // Note: protocol.Error expects `| null` for optional fields (BARE protocol) (value): protocol.ToClient => ({ body: { tag: "Error" as const, @@ -325,7 +334,10 @@ export async function processMessage< cbor.encode(value.metadata), ) : null, - actionId: value.actionId ?? null, + actionId: + value.actionId !== undefined + ? value.actionId + : null, }, }, }), diff --git a/rivetkit-typescript/packages/rivetkit/src/client/utils.ts b/rivetkit-typescript/packages/rivetkit/src/client/utils.ts index 2aa66ac858..3c4506a6b8 100644 --- a/rivetkit-typescript/packages/rivetkit/src/client/utils.ts +++ b/rivetkit-typescript/packages/rivetkit/src/client/utils.ts @@ -157,7 +157,7 @@ export async function sendHttpRequest< message: bare.message, metadata: bare.metadata ? cbor.decode(new Uint8Array(bare.metadata)) - : null, + : undefined, }), ); } catch (error) { diff --git a/rivetkit-typescript/packages/rivetkit/src/common/router.ts b/rivetkit-typescript/packages/rivetkit/src/common/router.ts index f86e68437c..530f26ec73 100644 --- a/rivetkit-typescript/packages/rivetkit/src/common/router.ts +++ b/rivetkit-typescript/packages/rivetkit/src/common/router.ts @@ -82,7 +82,7 @@ export function handleRouteError(error: unknown, c: HonoContext) { group: value.group, code: value.code, message: value.message, - metadata: value.metadata ?? null, + metadata: value.metadata, }), // BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer (value): protocol.HttpResponseError => ({ diff --git a/rivetkit-typescript/packages/rivetkit/src/schemas/client-protocol-zod/mod.ts b/rivetkit-typescript/packages/rivetkit/src/schemas/client-protocol-zod/mod.ts index ca70a30023..8460f713ac 100644 --- a/rivetkit-typescript/packages/rivetkit/src/schemas/client-protocol-zod/mod.ts +++ b/rivetkit-typescript/packages/rivetkit/src/schemas/client-protocol-zod/mod.ts @@ -15,7 +15,7 @@ export const ErrorSchema = z.object({ group: z.string(), code: z.string(), message: z.string(), - metadata: z.unknown().nullable(), + metadata: z.unknown().optional(), actionId: OptionalUintSchema, }); export type Error = z.infer; @@ -89,7 +89,7 @@ export const HttpResponseErrorSchema = z.object({ group: z.string(), code: z.string(), message: z.string(), - metadata: z.unknown().nullable(), + metadata: z.unknown().optional(), }); export type HttpResponseError = z.infer;