Skip to content

Commit 81e4164

Browse files
author
mozmo15
committed
fix(server): prioritize zod issues and format them
1 parent fe9c07b commit 81e4164

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/server/zod-compat.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,19 @@ export function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | un
195195
*/
196196
export function getParseErrorMessage(error: unknown): string {
197197
if (error && typeof error === 'object') {
198+
// When present, prioritize zod issues and format as a message and path
199+
if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) {
200+
return error.issues
201+
.map(
202+
(i: { message: string; path: string[] }) =>
203+
`${i.message} at ${i.path.length ? 'path ' + i.path.join('.') : 'object root'}`
204+
)
205+
.join('\n');
206+
}
198207
// Try common error structures
199208
if ('message' in error && typeof error.message === 'string') {
200209
return error.message;
201210
}
202-
if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) {
203-
const firstIssue = error.issues[0];
204-
if (firstIssue && typeof firstIssue === 'object' && 'message' in firstIssue) {
205-
return String(firstIssue.message);
206-
}
207-
}
208211
// Fallback: try to stringify the error
209212
try {
210213
return JSON.stringify(error);

0 commit comments

Comments
 (0)