Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when file is not found #29

Closed
techtonik opened this issue Jan 6, 2017 · 5 comments
Closed

Better error message when file is not found #29

techtonik opened this issue Jan 6, 2017 · 5 comments
Assignees
Labels
Milestone

Comments

@techtonik
Copy link

techtonik commented Jan 6, 2017

If parsed file does not exist, the untangle message is rather cryptic:

Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import untangle
>>> untangle.parse('sfsdf')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\untangle.py", line 143, in parse
    parser.parse(StringIO(filename))
  File "C:\Python27\lib\xml\sax\expatreader.py", line 110, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "C:\Python27\lib\xml\sax\xmlreader.py", line 125, in parse
    self.close()
  File "C:\Python27\lib\xml\sax\expatreader.py", line 225, in close
    self.feed("", isFinal = 1)
  File "C:\Python27\lib\xml\sax\expatreader.py", line 217, in feed
    self._err_handler.fatalError(exc)
  File "C:\Python27\lib\xml\sax\handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:0: syntax error
@stchris stchris added the bug label Mar 9, 2017
@stchris stchris added this to the 1.1.1 milestone Mar 9, 2017
@stchris
Copy link
Owner

stchris commented Mar 9, 2017

The issue here is that parse tries to be clever and interpret the given string as an XML input string and not a filename. I think the solution here is to have dedicated methods for parsing files and strings.

@stchris stchris self-assigned this Mar 9, 2017
@techtonik
Copy link
Author

Having a specific parsefile() method would help, I guess. And the error message could be improved too to something like like - parse() error - invalid argument contents or filename is not found.

@stchris
Copy link
Owner

stchris commented Mar 10, 2017

Regarding your point about the error message: the problem is that the API for parse() now states that Raises xml.sax.SAXParseException if something goes wrong during parsing. so catching that would break the API :/

@techtonik
Copy link
Author

Deprecate filename argument for this function and provide parsefile()?

I also think that it may be a source of security vulnerability if untangle is used to process input from the web.

@stchris stchris modified the milestones: 2.0.0, 1.1.1 May 7, 2017
@stchris
Copy link
Owner

stchris commented Jul 1, 2022

Closing this in favor of #87

@stchris stchris closed this as completed Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants