1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-31 07:44:22 +03:00

Add better parser errors (#1553)

Old SVGO errors were not very helpful. Packages like cssnano
(postcss-svgo) had to deal with a lot of issues which are hard to debug
with old errors.

```
Error: Error in parsing SVG: Unquoted attribute value
Line: 1
Column: 29
Char: 6
File: input.svg
```

New errors are more informative and may solve many struggles

```
Error: SvgoParserError: input.svg:2:29: Unquoted attribute value

  1 | <svg viewBox="0 0 120 120">
> 2 |   <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/>
    |                             ^
  3 | </svg>
  4 |
```
This commit is contained in:
Bogdan Chadkin
2021-09-12 01:09:10 +03:00
committed by GitHub
parent e8321f0c27
commit 77102ed096
12 changed files with 327 additions and 139 deletions

View File

@ -341,46 +341,4 @@ describe('svg2js', function () {
});
});
});
describe('malformed svg', function () {
var filepath = PATH.resolve(__dirname, './test.bad.svg'),
root,
error;
beforeAll(function (done) {
FS.readFile(filepath, 'utf8', function (err, data) {
if (err) {
throw err;
}
try {
root = SVG2JS(data);
} catch (e) {
error = e;
}
done();
});
});
describe('root', function () {
it('should have property "error"', function () {
expect(root).toHaveProperty('error');
});
});
describe('root.error', function () {
it('should be "Error in parsing SVG: Unexpected close tag"', function () {
expect(root.error).toEqual(
'Error in parsing SVG: Unexpected close tag\nLine: 10\nColumn: 15\nChar: >'
);
});
});
describe('error', function () {
it('should not be thrown', function () {
expect(error).not.toEqual(expect.anything());
});
});
});
});