Repository navigation
Better parser errors
This minor release makes malformed SVG easier to diagnose and parser failures easier to handle programmatically.
What changed
- Parser errors now include concise source context with a caret pointing to the exact error location
- Source snippets are bounded to 80 columns and one surrounding line on each side, with ellipses showing omitted content
- Parser
Errorobjects now expose zero-basedlineandcolumnproperties, plus the renderedsnippet - Empty and whitespace-only input now reports
SVG input is emptyexplicitly - Error messages no longer include issue tracker guidance
For example, long input is truncated both vertically and horizontally while preserving the error location:
Expected > (2:76)
…
<g aria-label="Decorative curve">
…20 C30 40, 50 60, 70 80 S110 120, 130 140" fill="none" stroke"currentColor" />
^
</g>
…
The error metadata can be handled independently of the human-readable message:
try {
parse(source);
} catch (error) {
console.log(error.line, error.column, error.snippet);
}Note: The human-readable text of parser errors has changed. Consumers matching exact error messages should update their expectations.
Install or update with:
npm install svg-parser@2.1.0Thanks to Christopher Pfohl for contributing structured error metadata.
Full changelog: v2.0.5...v2.1.0