Skip to content

Parse errors carry line/column + context snippet - #4

Merged
conorbronsdon merged 1 commit into
mainfrom
error-positions
Jul 8, 2026
Merged

Parse errors carry line/column + context snippet#4
conorbronsdon merged 1 commit into
mainfrom
error-positions

Conversation

@conorbronsdon

Copy link
Copy Markdown
Owner

Adds the suite-shared position-aware parse-error module, following the pattern established in mojo-xml#3.

  • src/url/errors.mojo — verbatim copy of the suite's errors.mojo (md5-verified identical to mojo-xml's): line_col maps a byte offset to a 1-based (line, byte-column) pair; parse_error renders <msg> at line <L>, column <C>: '<snippet>' with a whitespace-trimmed, ~30-byte, UTF-8-safe snippet window. Both exported from the url package.
  • No wiring into parse paths — deliberately. mojo-url mirrors urllib.parse, which is permissive by design: the library has no raising parse sites (port() returns -1 for non-numeric; parse_qs only propagates Dict-op raises with no byte offset). Nothing raised before and nothing raises now, preserving CPython parity. The helpers are ready for future strict/validating APIs.
  • 21 unit tests in test/test_errors.mojo covering every documented edge case (clamping, CRLF, snippet truncation on each side, UTF-8 window nudge, plus a long-single-line URL case), registered in the pixi test task and CI.

Verification: full suite green — 38/38 existing tests including 173/173 CPython-fixture byte-match and 42/42 RFC 3986 §5.4 urljoin table, 21/21 new tests; format gate and fixture-regeneration gate pass on the committed tree.

🤖 Generated with Claude Code

Copies the suite-shared errors.mojo pattern from mojo-xml verbatim:
line_col maps a byte offset to a 1-based (line, byte-column) pair and
parse_error renders "<msg> at line <L>, column <C>: <snippet>" with a
trimmed, ~30-byte, UTF-8-safe snippet window.

mojo-url mirrors urllib.parse, which is permissive by design — the
library has no raising parse paths, so no existing behavior or message
changes. The helpers are exported (url.line_col / url.parse_error) and
ready for future strict/validating APIs. 21 unit tests cover every
documented edge case; test task and CI updated to run them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@conorbronsdon
conorbronsdon merged commit e7c494a into main Jul 8, 2026
1 check passed
@conorbronsdon
conorbronsdon deleted the error-positions branch July 8, 2026 05:01
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