Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 1505009

Browse files
committed
chore(core): reduce dupe action request schema validation (#1168)
1 parent 65d1d68 commit 1505009

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

packages/core/src/actor/router-endpoints.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -427,41 +427,23 @@ export async function handleAction(
427427
logger().debug("handling action", { actionName, encoding });
428428

429429
// Validate incoming request
430-
let actionArgs: unknown[];
430+
let body: unknown;
431431
if (encoding === "json") {
432432
try {
433-
const body = await c.req.json();
434-
435-
// Validate using the action schema
436-
const result = protoHttpAction.ActionRequestSchema.safeParse(body);
437-
if (!result.success) {
438-
throw new errors.InvalidActionRequest("Invalid action request format");
439-
}
440-
441-
actionArgs = result.data.a;
433+
body = await c.req.json();
442434
} catch (err) {
443435
if (err instanceof errors.InvalidActionRequest) {
444436
throw err;
445437
}
446-
throw new errors.InvalidActionRequest("Invalid JSON");
438+
throw new errors.InvalidActionRequest(
439+
`Invalid JSON: ${stringifyError(err)}`,
440+
);
447441
}
448442
} else if (encoding === "cbor") {
449443
try {
450444
const value = await c.req.arrayBuffer();
451445
const uint8Array = new Uint8Array(value);
452-
const deserialized = await deserialize(
453-
uint8Array as unknown as InputData,
454-
encoding,
455-
);
456-
457-
// Validate using the action schema
458-
const result =
459-
protoHttpAction.ActionRequestSchema.safeParse(deserialized);
460-
if (!result.success) {
461-
throw new errors.InvalidActionRequest("Invalid action request format");
462-
}
463-
464-
actionArgs = result.data.a;
446+
body = await deserialize(uint8Array as unknown as InputData, encoding);
465447
} catch (err) {
466448
throw new errors.InvalidActionRequest(
467449
`Invalid binary format: ${stringifyError(err)}`,
@@ -471,6 +453,21 @@ export async function handleAction(
471453
return assertUnreachable(encoding);
472454
}
473455

456+
// Validate using the action schema
457+
let actionArgs: unknown[];
458+
try {
459+
const result = protoHttpAction.ActionRequestSchema.safeParse(body);
460+
if (!result.success) {
461+
throw new errors.InvalidActionRequest("Invalid action request format");
462+
}
463+
464+
actionArgs = result.data.a;
465+
} catch (err) {
466+
throw new errors.InvalidActionRequest(
467+
`Invalid schema: ${stringifyError(err)}`,
468+
);
469+
}
470+
474471
// Invoke the action
475472
let actor: AnyActorInstance | undefined;
476473
let conn: AnyConn | undefined;

0 commit comments

Comments
 (0)