diff --git a/src/server/zod-compat.ts b/src/server/zod-compat.ts index 9d25a5efc..489350b75 100644 --- a/src/server/zod-compat.ts +++ b/src/server/zod-compat.ts @@ -195,16 +195,18 @@ export function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | un */ export function getParseErrorMessage(error: unknown): string { if (error && typeof error === 'object') { + // When present, prioritize zod issues and format as a message and path + if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) { + return error.issues + .map((i: { message: string; path?: string[] }) => + Array.isArray(i.path) ? `${i.message} at ${i.path.length ? 'path ' + i.path.join('.') : 'object root'}` : i.message + ) + .join('\n'); + } // Try common error structures if ('message' in error && typeof error.message === 'string') { return error.message; } - if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) { - const firstIssue = error.issues[0]; - if (firstIssue && typeof firstIssue === 'object' && 'message' in firstIssue) { - return String(firstIssue.message); - } - } // Fallback: try to stringify the error try { return JSON.stringify(error);