feat(svg): every reader error names the offending element and why#184
Merged
Conversation
Accepting a real-world SVG that won't render now explains itself instead of a cryptic message: - each per-element error is wrapped with element context — the deepest failing element (not its wrapping <g>), its attributes (long values like d truncated), then the original reason and the supported set: 'in <circle fill="rebecca-purple" …>: unsupported SVG colour … — use #hex, rgb()/rgba(), a CSS colour name, …' - a blank result names what was dropped: 'no drawable geometry — skipped text; this reader renders vector shapes only', not a bare 'no geometry' - shape lowering (rect/ellipse/points → path data) extracted to SvgShapeLowering (this change crossed 500 LOC; back to 469) with its own 4-test unit; the reader's per-element try wraps once, recursion stays outside so child errors never double-wrap +8 tests (4 error-context in SvgIconTest, 4 in SvgShapeLoweringTest)
num()/viewBox()/transform parsing routed through a parseNumber helper that throws '<field> must be a number, got <value>' with the cause chained, instead of leaking the raw JDK 'For input string'. Drops a dead emitLayer param and fixes the describe() truncation off-by-one. Adds negative tests.
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.
Second of the two requested follow-ups: when you accept a real-world SVG and something won't render, the error now explains itself — which element, which attribute, and how to fix it — instead of a cryptic one-liner.
Before → after
How
<tag attr="…">, longdtruncated). Recursion stays outside the try, so a nested error pinpoints the deepest failing element, never its wrapping<g>, and never double-wraps (pinned by a test).NumberFormatException(bad coordinate) is a subclass ofIllegalArgumentException, so it gets element context too.Housekeeping
This change pushed
SvgIconReaderto 514 LOC; I extracted the shape-lowering (rect/ellipse/points→ path data) to a focusedSvgShapeLoweringhelper (reader back to 469) with its own 4-test unit — the PR-85 discipline.Verification
./mvnw verify -pl .→ BUILD SUCCESS, +8 tests (4 error-context: element-named colour, deepest-not-group, long-attr truncation, blank-explains-skip; 4 shape-lowering). Existing 25 SvgIconTest cases stay green — the wrapping preserves everyhasMessageContainingsubstring. No public API change (messages only). Independent of any open branch.Pairs with #183 (block alignment) — the two things you asked for.