Skip to content

Commit 8567cdb

Browse files
committed
docs(api): zodIssuesToFields 的条目数不再等于 zod issue 数 (#5014)
联合失配现在除了联合自身那条,还会追加解释它的分支条目,所以 `fields.length` 要读作「字段错误条数」而不是「zod issue 条数」。 这段示例正是对外推荐 `zodIssuesToFields` 的地方。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FTszibd6C8sUCCZnM4VcrL
1 parent fcd20da commit 8567cdb

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎content/docs/api/error-handling-server.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ import { zodIssuesToFields } from '@objectstack/rest';
176176
// `too_small` becomes `min_length` / `min_value` / `min_items` depending on what
177177
// was too small, and a MISSING property becomes `required` instead of the
178178
// `invalid_type` Zod reports for it.
179+
//
180+
// One entry per issue is the common case, NOT a guarantee: Zod folds a failed
181+
// `z.union` into a single issue whose message is the bare "Invalid input", so a
182+
// union failure produces that entry PLUS the entries of the branch that explains
183+
// it, addressed with the union's own path (#5014). Read `fields.length` as the
184+
// number of field errors, never as the number of Zod issues.
179185
function createValidationError(zodError: z.ZodError, input?: unknown): AppError {
180186
const fields = zodIssuesToFields(zodError.issues, input);
181187

0 commit comments

Comments
 (0)