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:
parent
11f8b76257
commit
b69d20a300
|
|
@ -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":{}',
|
||||
|
|
|
|||
|
|
@ -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 ?? "",
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue