fix(errors): report union input issues at the union's path

Zod reports union branch issues relative to the union, so a missing
union-typed argument such as trace_application_feature's seed was
reported at the request root, once per branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Iwakurakaoru0822
2026-10-06 22:02:25 -07:00
co-authored by Claude Opus 5.5
parent b6d9acca63
commit bddeb634b5
2 changed files with 39 additions and 2 deletions
+23
View File
@@ -26,4 +26,27 @@ describe("input issue projection", () => {
},
]);
});
it("reports union branch issues at the union's path once", () => {
const schema = z.object({
seed: z.union([
z.object({ value: z.string().min(1) }),
z.object({ value: z.literal(""), match: z.literal("exact") }),
]),
});
const missing = schema.safeParse({});
if (missing.success) throw new Error("expected invalid input");
expect(projectInputIssues(missing.error.issues, {})).toEqual([
{ path: ["seed"], reason: "missing_argument", expected: "object" },
]);
const input = { seed: { value: 1 } };
const nested = schema.safeParse(input);
if (nested.success) throw new Error("expected invalid input");
expect(projectInputIssues(nested.error.issues, input)).toEqual(
expect.arrayContaining([
{ path: ["seed", "value"], reason: "invalid_type", expected: "string" },
]),
);
});
});