Skip to content

Commit abb4ae2

Browse files
authored
Revert "fix(rivetkit): standardize error metadata return type (#3438)"
This reverts commit 0c93402.
1 parent 0c93402 commit abb4ae2

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

rivetkit-typescript/packages/rivetkit/src/actor/protocol/old.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -299,29 +299,20 @@ export async function processMessage<
299299
errorData,
300300
TO_CLIENT_VERSIONED,
301301
ToClientSchema,
302-
// JSON: metadata is the raw value (keep as undefined if not present)
303-
(value): ToClientJson => {
304-
const val: any = {
305-
group: value.group,
306-
code: value.code,
307-
message: value.message,
308-
actionId:
309-
value.actionId !== undefined
310-
? value.actionId
311-
: null,
312-
};
313-
if (value.metadata !== undefined) {
314-
val.metadata = value.metadata;
315-
}
316-
return {
317-
body: {
318-
tag: "Error" as const,
319-
val,
302+
// JSON: metadata is the raw value
303+
(value): ToClientJson => ({
304+
body: {
305+
tag: "Error" as const,
306+
val: {
307+
group: value.group,
308+
code: value.code,
309+
message: value.message,
310+
metadata: value.metadata ?? null,
311+
actionId: value.actionId ?? null,
320312
},
321-
};
322-
},
313+
},
314+
}),
323315
// BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
324-
// Note: protocol.Error expects `| null` for optional fields (BARE protocol)
325316
(value): protocol.ToClient => ({
326317
body: {
327318
tag: "Error" as const,
@@ -334,10 +325,7 @@ export async function processMessage<
334325
cbor.encode(value.metadata),
335326
)
336327
: null,
337-
actionId:
338-
value.actionId !== undefined
339-
? value.actionId
340-
: null,
328+
actionId: value.actionId ?? null,
341329
},
342330
},
343331
}),

rivetkit-typescript/packages/rivetkit/src/client/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export async function sendHttpRequest<
157157
message: bare.message,
158158
metadata: bare.metadata
159159
? cbor.decode(new Uint8Array(bare.metadata))
160-
: undefined,
160+
: null,
161161
}),
162162
);
163163
} catch (error) {

rivetkit-typescript/packages/rivetkit/src/common/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function handleRouteError(error: unknown, c: HonoContext) {
8282
group: value.group,
8383
code: value.code,
8484
message: value.message,
85-
metadata: value.metadata,
85+
metadata: value.metadata ?? null,
8686
}),
8787
// BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
8888
(value): protocol.HttpResponseError => ({

rivetkit-typescript/packages/rivetkit/src/schemas/client-protocol-zod/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const ErrorSchema = z.object({
1515
group: z.string(),
1616
code: z.string(),
1717
message: z.string(),
18-
metadata: z.unknown().optional(),
18+
metadata: z.unknown().nullable(),
1919
actionId: OptionalUintSchema,
2020
});
2121
export type Error = z.infer<typeof ErrorSchema>;
@@ -89,7 +89,7 @@ export const HttpResponseErrorSchema = z.object({
8989
group: z.string(),
9090
code: z.string(),
9191
message: z.string(),
92-
metadata: z.unknown().optional(),
92+
metadata: z.unknown().nullable(),
9393
});
9494
export type HttpResponseError = z.infer<typeof HttpResponseErrorSchema>;
9595

0 commit comments

Comments
 (0)