Skip to content

Sharpen HAR parser error messages for method and url#2

Merged
marky224 merged 1 commit into
mainfrom
polish/har-parser-errors
May 2, 2026
Merged

Sharpen HAR parser error messages for method and url#2
marky224 merged 1 commit into
mainfrom
polish/har-parser-errors

Conversation

@marky224
Copy link
Copy Markdown
Owner

@marky224 marky224 commented May 2, 2026

Summary

  • parse_har now distinguishes missing key vs wrong type vs empty string for request.method and request.url — three failure modes that pointed at different upstream bugs but previously collapsed into one "missing" message.
  • Field-error messages now prefix with HAR entry[0] (<url>): so the user can identify which captured request failed (real-world HARs have many entries; v1 parses entries[0] only). Label degrades to HAR entry[0]: when the URL itself is the bad field.
  • Surfaced via Claude Web UI testing of the hosted demo's /api/analyze parser-rejection path on 2026-05-02; both items came back as cheap parser-only follow-ups.

Example new messages:

HAR entry[0] (https://api.example.com/foo): request.method is empty.
HAR entry[0] (https://api.example.com/foo): request.method must be a string, got int.
HAR entry[0]: request.url is missing.

Test plan

  • pytest — 335 passed, including 6 new tests covering all method/url failure paths plus the label-with-URL and label-fallback cases
  • ruff check . clean
  • ruff format --check . clean
  • mypy clean
  • Lambda handler test still asserts on the 400 detail (substring "method") — passes unchanged
  • After merge: re-run the Claude Web HAR mutation test against the deployed demo and confirm the new message appears in the red error banner

🤖 Generated with Claude Code

parse_har previously collapsed three failure modes into one message
("missing"): the key was absent, the value was wrong type, or the
value was an empty string. They point at different upstream bugs
(non-conformant HAR tool, corrupt capture, schema violation), so
they now produce three distinct messages each for both required
fields:

  HAR entry[0] (<url>): request.method is missing.
  HAR entry[0] (<url>): request.method must be a string, got int.
  HAR entry[0] (<url>): request.method is empty.

The same split applies to request.url. Real-world HARs commonly
contain dozens of entries; v1 only parses entries[0], so the URL
parenthetical is what tells the user which captured request actually
failed in their archive. When the URL itself is the bad field the
label degrades to "HAR entry[0]:" without a parenthetical.

Tests cover all six failure paths plus the label-with-URL and
label-fallback cases. Lambda handler test still passes — its
assertion only checks for the substring "method" in the 400 detail.

CHANGELOG [Unreleased] / Fixed updated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@marky224 marky224 merged commit cf934dc into main May 2, 2026
14 checks passed
@marky224 marky224 deleted the polish/har-parser-errors branch May 2, 2026 18:37
@marky224 marky224 mentioned this pull request May 2, 2026
6 tasks
marky224 added a commit that referenced this pull request May 2, 2026
HAR-tab UX polish, Report action wiring, and parser hardening rolled
up from PRs #2, #3, and the action-button work on this branch:

- HAR picker meta line shows file size, capture date, unique-host count
- Report Re-run / Export markdown buttons wired up (previously inert)
- Lambda /api/analyze returns 400 with detail on malformed HAR entries
- HAR parser distinguishes missing/wrong-type/empty for method+url
- HAR httpVersion normalized to match live runner's protocol format

schema_version stays at 1.0 — no Report shape changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant