commit c8d387e64851a48d077b933b80687a8afa9e2a7e Author: Radek Pazdera rpazdera@redhat.com Date: Wed Oct 9 11:53:36 2013 +0200
XmlParser: Incorrect execption handling
Different exception is raised when an included file didn't exist. In that case, controller would crash with an exception.
This commit adds an additional branch to handle generic exceptions too.
Issue #46
Signed-off-by: Radek Pazdera rpazdera@redhat.com Signed-off-by: Jiri Pirko jiri@resnulli.us
lnst/Common/XmlParser.py | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) --- diff --git a/lnst/Common/XmlParser.py b/lnst/Common/XmlParser.py index c60b410..4cde0b4 100644 --- a/lnst/Common/XmlParser.py +++ b/lnst/Common/XmlParser.py @@ -81,7 +81,7 @@ class XmlParser(object): def _parse(self, path): try: doc = etree.parse(path) - except Exception as err: + except etree.LxmlError as err: # A workaround for cases when lxml (quite strangely) # sets the filename to <string>. if err.error_log[0].filename == "<string>": @@ -94,6 +94,13 @@ class XmlParser(object): exc = XmlProcessingError(err.error_log[0].message) exc.set_loc(loc) raise exc + except Exception as err: + loc = {"file": os.path.basename(self._path), + "line": None, + "col": None} + exc = XmlProcessingError(str(err)) + exc.set_loc(loc) + raise exc
return doc
lnst-developers@lists.fedorahosted.org