File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -195,16 +195,19 @@ export function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | un
195195 */
196196export 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 ) ;
You can’t perform that action at this time.
0 commit comments