Parse errors carry line/column + context snippet - #4
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'serrors.mojo(md5-verified identical to mojo-xml's):line_colmaps a byte offset to a 1-based (line, byte-column) pair;parse_errorrenders<msg> at line <L>, column <C>: '<snippet>'with a whitespace-trimmed, ~30-byte, UTF-8-safe snippet window. Both exported from theurlpackage.urllib.parse, which is permissive by design: the library has no raising parse sites (port()returns -1 for non-numeric;parse_qsonly 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.test/test_errors.mojocovering 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 pixitesttask 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