agent_patch
runs/2026-02-27__21-30-28__gpt-5-4/flux-pr-4843/flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-4/agent-logs/agent.patch
3098 bytes
diff --git a/tmp/agent-patch-flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/classic/tests/error-utils.test.ts b/app/packages/zod/src/v4/classic/tests/error-utils.test.ts
index f6b2d3e..384f535 100644
--- a/tmp/agent-patch-flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/classic/tests/error-utils.test.ts
+++ b/app/packages/zod/src/v4/classic/tests/error-utils.test.ts
@@ -416,6 +416,42 @@ test("z.treeifyError 2", () => {
`);
});
+test("z.treeifyError branded primitive", () => {
+ const schema = z.object({
+ id: z.string().brand<"id">(),
+ });
+
+ const result = schema.safeParse({
+ id: 1234,
+ });
+
+ expect(result.success).toBe(false);
+
+ const err = z.treeifyError(result.error!);
+ expectTypeOf(err).toEqualTypeOf<{
+ errors: string[];
+ properties?: {
+ id?: {
+ errors: string[];
+ };
+ };
+ }>();
+ expectTypeOf(err.properties?.id).toEqualTypeOf<{ errors: string[] } | undefined>();
+
+ expect(err).toMatchInlineSnapshot(`
+ {
+ "errors": [],
+ "properties": {
+ "id": {
+ "errors": [
+ "Invalid input: expected string, received number",
+ ],
+ },
+ },
+ }
+ `);
+});
+
test("z.prettifyError", () => {
expect(z.prettifyError(result.error!)).toMatchInlineSnapshot(`
"✖ Unrecognized key: "extra"
diff --git a/tmp/agent-patch-flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/errors.ts b/app/packages/zod/src/v4/core/errors.ts
index 699c81f..8502713 100644
--- a/tmp/agent-patch-flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-4/app/packages/zod/src/v4/core/errors.ts
+++ b/app/packages/zod/src/v4/core/errors.ts
@@ -1,5 +1,6 @@
import type { $ZodCheck, $ZodStringFormats } from "./checks.js";
import { $constructor } from "./core.js";
+import type { $brand } from "./core.js";
import type { $ZodType } from "./schemas.js";
import * as util from "./util.js";
@@ -295,7 +296,13 @@ export function formatError<T>(error: $ZodError, _mapper?: any) {
return fieldErrors;
}
-export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]]
+type StripPrimitiveBrand<T> = T extends infer Primitive & $brand<any>
+ ? Primitive extends util.Primitive
+ ? StripPrimitiveBrand<Primitive>
+ : T
+ : T;
+
+type _ZodErrorTree<T, U = string> = T extends [any, ...any[]]
? { errors: U[]; items?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
: T extends any[]
? { errors: U[]; items?: Array<$ZodErrorTree<T[number], U>> }
@@ -303,6 +310,8 @@ export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]]
? { errors: U[]; properties?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
: { errors: U[] };
+export type $ZodErrorTree<T, U = string> = _ZodErrorTree<StripPrimitiveBrand<T>, U>;
+
export function treeifyError<T>(error: $ZodError<T>): $ZodErrorTree<T>;
export function treeifyError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodErrorTree<T, U>;
export function treeifyError<T>(error: $ZodError, _mapper?: any) {