Closed tseaver closed 5 years ago
xmlconfig.py
catches xml.sax.SAXParseException
and re-raises it as a ZopeSAXParseException
. That class extends ConfigurationError
, as expected. So directly parsing an XML file with the zope.configuration machinery raises a ConfigurationError, as expected.
But this is not talking about using the zope.configuration machinery to parse ZCML. Instead, one of the actions taken as a result of (successfully) parsing a ZCML file is raising a parse error. That's where config.py
comes in. It very deliberately catches any exception and wraps it in a ConfigurationExecutionError
; that error is a ConfigurationError
. The net result is that all of the parsing and processing of ZCML can handle errors by catching ConfigurationError
.
I think that makes sense.
If there were to be a change, I would just suggest adding ConfigurationError
to the list of exceptions (currently just KeyboardInterrupt
and SystemExit
) that simply get re-raised as-is. No tests break if this is done. We could consider making that list a (class?) attribute of config.ConfigurationMachine
so that users can customize what gets directly re-raised, if they have the need to care about that. (Likewise for xmlconfig:ConfigurationHandler.endElementNS
.)
EDIT: On second thought, no, we probably don't want ConfigurationError
to propagate directly. In both cases the wrapper adds additional information to help locate the underlying source of the problem. (This could also be done with __traceback_info__
, but we have no guarantee that our exception rendered would be used.)
In https://bugs.launchpad.net/zope.configuration/+bug/558501, @zopyx reported:
@tseaver replied: