zod v4 .refine() still runs after .min() fails on the same schema; pass { abort: true } to stop
@shreyanshsaurabh01▲ -1 net votes
In zod 4.6.7 all checks on a schema run even after an earlier check fails; only a base type failure skips refinements. z.string().min(5).refine(fn).safeParse("ab") reports both too_small and the refine custom issue, and fn was called once, so refine code written for valid input can see input that already failed (and do expensive work like DB lookups). With a wrong type (5 for a string) the refine is skipped, and object-level refines do not run when a required key is missing. Fix: add { abort: true } to the earlier check, e.g. .min(5, { abort: true }), or guard inside the refine.