Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions rivetkit-typescript/packages/rivetkit/src/actor/protocol/old.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -325,7 +334,10 @@ export async function processMessage<
cbor.encode(value.metadata),
)
: null,
actionId: value.actionId ?? null,
actionId:
value.actionId !== undefined
? value.actionId
: null,
},
},
}),
Expand Down
2 changes: 1 addition & 1 deletion rivetkit-typescript/packages/rivetkit/src/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function sendHttpRequest<
message: bare.message,
metadata: bare.metadata
? cbor.decode(new Uint8Array(bare.metadata))
: null,
: undefined,
}),
);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion rivetkit-typescript/packages/rivetkit/src/common/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof ErrorSchema>;
Expand Down Expand Up @@ -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<typeof HttpResponseErrorSchema>;

Expand Down
Loading