Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/server/zod-compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading