-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
convert ElementTree.ParseError to xsdata.exceptions.ParserError #571
Comments
thanks for reporting @FirefoxMetzger, The xsdata exceptions are due for a refactor, they are a bit messy and not very consistent, but I don't have the energy to deal with this now. I merged a quick patch to wrap all xml syntax errors from all handlers. Note to self??? |
After looking to code such as: try:
parser = sax.make_parser() # nosec
parser.setFeature(sax.handler.feature_namespaces, True)
parser.setContentHandler(self)
parser.parse(source)
return self.close()
except SAXException as e:
raise SyntaxError(e) I think it would be better to not eat original exceptions, but wrap them: try:
parser = sax.make_parser() # nosec
parser.setFeature(sax.handler.feature_namespaces, True)
parser.setContentHandler(self)
parser.parse(source)
return self.close()
except SAXException as e:
raise SyntaxError from e |
Never mind, I see that in such cases, exception chaining occurs automatically. From the docs: |
@neriusmika That is almost correct. The If you write something like try:
raise ValueError()
except ValueError():
raise IndexError() then you will get a stack-trace mentioning try:
raise ValueError()
except ValueError() as e:
raise IndexError() from e your stack trace will get a line mentioning Arguably only relevant if you have complicated logic in your except block and you need to differentiate expected exceptions from unexpected exceptions while debugging and within such a block. Note also that if you write try:
raise ValueError()
except ValueError():
raise IndexError() from None you will eat all previous exceptions (here the ValueError) and only raise an |
More of a proposal than a bug. If you don't have
lxml
installed or choose to explicitly parse with the built-in ElementTree then ElementTree parse errors are forwarded as-is. I think it could be nice if they could be converted to the xsdata internal ParserError. It makes downstream code cleaner and less specific to xsdata's choice of implementation.Consider the following snippet
at the moment it results in
and handling it (jointly with other parse errors) looks something like
The text was updated successfully, but these errors were encountered: