Skip to content

Commit 05736c4

Browse files
Improve validation error message (#632)
1 parent effb346 commit 05736c4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

packages/libs/restate-sdk-core/src/serde_api.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,41 @@ class StandardSchemaSerde<
112112
// Standard Schema validate can return a Promise, but Serde must be synchronous
113113
if (result && typeof result === "object" && "then" in result) {
114114
throw new TypeError(
115-
"Async validation is not supported in Serde. The schema must support synchronous validation."
115+
"Async validation is not supported in Serde. Restate SDK supports only synchronous validation."
116116
);
117117
}
118118

119119
if (result.issues) {
120120
const errorMessages = result.issues
121-
.map((issue: StandardSchemaV1.Issue) => issue.message)
122-
.join(", ");
121+
.map(formatStandardSchemaIssue)
122+
.join("\n");
123123
throw new TypeError(
124-
`Standard schema validation failed: [${errorMessages}]`
124+
`Standard schema validation failed:\n${errorMessages}`
125125
);
126126
}
127127

128128
return result.value as StandardSchemaV1.InferOutput<T>;
129129
}
130130
}
131131

132+
function formatStandardSchemaIssue(issue: StandardSchemaV1.Issue): string {
133+
if (issue.path && issue.path.length > 0) {
134+
const jsonPointer =
135+
"/" +
136+
issue.path
137+
.map((p) => {
138+
// Handle both PathSegment objects and primitive PropertyKey values
139+
if (typeof p === "object" && p !== null && "key" in p) {
140+
return String(p.key);
141+
}
142+
return String(p);
143+
})
144+
.join("/");
145+
return `* (at ${jsonPointer}) ${issue.message}`;
146+
}
147+
return `* ${issue.message}`;
148+
}
149+
132150
function isStandardJSONSchemaV1(standard: StandardSchemaV1.Props): boolean {
133151
return (
134152
standard != undefined &&

0 commit comments

Comments
 (0)