agent_patch
runs/2026-02-27__21-30-28__gpt-5-1-codex-mini/flux-pr-4843/flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/agent-logs/agent.patch
3588 bytes
diff --git a/tmp/agent-patch-flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/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..29d7eec 100644
--- a/tmp/agent-patch-flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/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,37 @@ test("z.treeifyError 2", () => {
`);
});
+test("z.treeifyError respects branded primitives", () => {
+ const schema = z.strictObject({
+ username: z.string().brand("Username"),
+ });
+ const result = schema.safeParse({
+ username: 123,
+ });
+ const err = z.treeifyError(result.error!);
+ expect(err).toMatchInlineSnapshot(`
+ {
+ "errors": [],
+ "properties": {
+ "username": {
+ "errors": [
+ "Invalid input: expected string, received number",
+ ],
+ },
+ },
+ }
+ `);
+
+ type ErrorTree = typeof err;
+ type IdentifierNode = NonNullable<ErrorTree["properties"]>["username"];
+ type HasProperties = IdentifierNode extends { properties: unknown } ? true : false;
+ type HasItems = IdentifierNode extends { items: unknown } ? true : false;
+
+ expectTypeOf<IdentifierNode>().toMatchTypeOf<{ errors: string[] } | undefined>();
+ expectTypeOf<HasProperties>().toEqualTypeOf<false>();
+ expectTypeOf<HasItems>().toEqualTypeOf<false>();
+});
+
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-1-codex-mini/app/packages/zod/src/v4/core/errors.ts b/app/packages/zod/src/v4/core/errors.ts
index 699c81f..28ea66b 100644
--- a/tmp/agent-patch-flux-pr-4843.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/app/packages/zod/src/v4/core/errors.ts
+++ b/app/packages/zod/src/v4/core/errors.ts
@@ -1,5 +1,5 @@
import type { $ZodCheck, $ZodStringFormats } from "./checks.js";
-import { $constructor } from "./core.js";
+import { $brand, $constructor } from "./core.js";
import type { $ZodType } from "./schemas.js";
import * as util from "./util.js";
@@ -295,14 +295,22 @@ export function formatError<T>(error: $ZodError, _mapper?: any) {
return fieldErrors;
}
-export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]]
- ? { errors: U[]; items?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
+type $RemoveBrand<T> = T extends infer U
+ ? U extends { [k in typeof $brand]: unknown }
+ ? Omit<U, typeof $brand>
+ : U
+ : never;
+
+type $ZodErrorTreeInternal<T, U = string> = T extends [any, ...any[]]
+ ? { errors: U[]; items?: { [K in keyof T]?: $ZodErrorTreeInternal<$RemoveBrand<T[K]>, U> } }
: T extends any[]
- ? { errors: U[]; items?: Array<$ZodErrorTree<T[number], U>> }
+ ? { errors: U[]; items?: Array<$ZodErrorTreeInternal<$RemoveBrand<T[number]>, U>> }
: T extends object
- ? { errors: U[]; properties?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
+ ? { errors: U[]; properties?: { [K in keyof T]?: $ZodErrorTreeInternal<$RemoveBrand<T[K]>, U> } }
: { errors: U[] };
+export type $ZodErrorTree<T, U = string> = $ZodErrorTreeInternal<$RemoveBrand<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) {