evil-mad / ink_extensions

Python dependencies for running Inkscape extensions outside of Inkscape
GNU General Public License v2.0
5 stars 5 forks source link

Traceback on failure to parse SVG file #7

Closed oskay closed 1 year ago

oskay commented 2 years ago
Traceback (most recent call last):
  File "axidraw_control.py", line 32, in <module>
    exit_status.run(e.affect)
  File "/Users/oskay/Library/Application Support/org.inkscape.Inkscape/config/inkscape/extensions/axidraw_deps/ink_extensions_utils/exit_status.py", line 26, in run
    return func(*args, **kwargs)
  File "/Users/oskay/Library/Application Support/org.inkscape.Inkscape/config/inkscape/extensions/axidraw_deps/ink_extensions/inkex.py", line 287, in affect
    self.parse()
  File "/Users/oskay/Library/Application Support/org.inkscape.Inkscape/config/inkscape/extensions/axidraw_deps/ink_extensions/inkex.py", line 210, in parse
    self.document = etree.parse(stream, parser=p)
  File "src/lxml/etree.pyx", line 3521, in lxml.etree.parse
  File "src/lxml/parser.pxi", line 1880, in lxml.etree._parseDocument
  File "src/lxml/parser.pxi", line 1900, in lxml.etree._parseFilelikeDocument
  File "src/lxml/parser.pxi", line 1795, in lxml.etree._parseDocFromFilelike
  File "src/lxml/parser.pxi", line 1201, in lxml.etree._BaseParser._parseDocFromFilelike
  File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
  File "/var/folders/y6/nbx15bws0k3767tqy2j797jsrtngm4/T/ink_ext_XXXXXX.svgEFV9K1", line 20
lxml.etree.XMLSyntaxError: xmlns:ns1: '&#38;#38;#38;ns_sfw;' is not a valid URI, line 20, column 40

This appears to be a namespace issue, similar to that seen at https://github.com/inkstitch/inkstitch/issues/772

The likely direct cause is an AI "Save for web" export: https://phabricator.wikimedia.org/T144827

Proper behavior here might be to catch any errors importing the document and report the error to the user, rather than causing a traceback. The error human-readable error "This SVG file contains an illegal namespace." from the second link seems close to what we might use.

Another approach would be to ignore that namespace if possible. See: https://localcoder.org/python-lxml-ignore-xml-declaration-errors

oskay commented 1 year ago

I can't seem to reproduce this issue at present; may need a new demonstration file to test it on.

oskay commented 1 year ago

Hasn't come up again in 6 months; closing for now. If you do come across this issue and can reproduce it, please comment here or open a new issue about it.