react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.74k stars 159 forks source link

isZodError: check if error.errors is actually an array #697

Closed ryanelian closed 3 months ago

ryanelian commented 3 months ago

ZodError type expects errors prop to be an array

export declare class ZodError<T = any> extends Error {
    issues: ZodIssue[];
    get errors(): ZodIssue[];
    constructor(issues: ZodIssue[]);
    format(): ZodFormattedError<T>;
    format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>;
    static create: (issues: ZodIssue[]) => ZodError<any>;
    toString(): string;
    get message(): string;
    get isEmpty(): boolean;
    addIssue: (sub: ZodIssue) => void;
    addIssues: (subs?: ZodIssue[]) => void;
    flatten(): typeToFlattenedError<T>;
    flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
    get formErrors(): typeToFlattenedError<T, string>;
}

And parseErrorSchema function expects an array:

https://github.com/react-hook-form/resolvers/blob/f7a4fd46af51a2a732c10ed652f5abfa532f4198/zod/src/zod.ts#L8-L11

Recently, we encountered an issue where the props can be undefined for some reason. I propose this PR to add a stricter check to prevent unexpected circumstances where the error.errors object is not an array.

Resolve #696

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 3.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: