From b69d20a300dba57783a810146f25dacb69f9b8a4 Mon Sep 17 00:00:00 2001 From: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Date: Tue, 13 Oct 2026 01:22:24 -0700 Subject: [PATCH] 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 --- src/browser/history/HarCapture.test.ts | 13 +++++++++++++ src/browser/history/HarSchema.ts | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/browser/history/HarCapture.test.ts b/src/browser/history/HarCapture.test.ts index 9614384cc..b931fda06 100644 --- a/src/browser/history/HarCapture.test.ts +++ b/src/browser/history/HarCapture.test.ts @@ -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":{}', diff --git a/src/browser/history/HarSchema.ts b/src/browser/history/HarSchema.ts index 069377f8a..add8c301e 100644 --- a/src/browser/history/HarSchema.ts +++ b/src/browser/history/HarSchema.ts @@ -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 ?? "", ); }