fix(captures): name the violated HAR schema constraint (#2708)

HAR validation reported only the AJV keyword, so a capture missing
`log.version` failed with "HAR schema validation failed: required." and
the caller could not tell which property to supply. Include AJV's
constraint message, which names the missing property, expected type, or
pattern without restating captured values.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822andClaude Opus 5.5 authored and GitHub committed 2026-10-13 16:22:24 +08:00
1 parent 11f8b76257
commit b69d20a300
2 files changed
+18 -1

No files matched your search

+13
View File
@@ -162,6 +162,19 @@ it("rejects identical duplicate core fields before schema validation", () => {
expect(() => decodeHarCapture(text, [])).toThrow("duplicate");
});
it("names the violated HAR schema constraint without restating capture values", () => {
expect(() =>
decodeHarCapture(
JSON.stringify({
log: { creator: { name: "x", version: "1" }, entries: [] },
}),
[],
),
).toThrow(
"HAR schema validation failed: required (must have required property 'version').",
);
});
it("preserves prototype-named producer members through the capture boundary", () => {
const text = JSON.stringify(historicalHar()).replace(
'"cache":{}',
+5 -1
View File
@@ -23,9 +23,13 @@ export const createHarValidator = (): ((value: unknown) => void) => {
allowMitmproxyAbsentPostData(value);
if (!validate(value)) {
const error = validate.errors?.[0];
// AJV messages name the violated constraint, such as the missing
// property, without restating any captured value.
throw new CaptureFormatError(
"format",
`HAR schema validation failed: ${error?.keyword ?? "unknown constraint"}.`,
error === undefined
? "HAR schema validation failed: unknown constraint."
: `HAR schema validation failed: ${error.keyword} (${error.message ?? "no detail"}).`,
error?.instancePath ?? "",
);
}