[Zope] Cool monkey patch to make tracebacks more useful :-)
Dieter Maurer
dieter at handshake.de
Thu Jul 14 17:43:45 EDT 2005
Lennart Regebro wrote at 2005-7-13 12:47 +0200:
> ...
>Ever noticed how it's near impossible to figure out what actually
>causes an error when you run functional tests? Can you fix that too?
>:-)
I solve this with a browser emulation that does not use HTTP for requests
but instead emulates "ZPublisher.Publish.publish" and therefore
can handle exceptions itself. It somehow looks like this:
def _internalRequest(self, path, query, method, headers, request_params,
catch_exc, response,
):
'''perform a request against the internal *url*.'''
from Zope import zpublisher_exception_hook as err_hook
from Zope import zpublisher_validated_hook as validated_hook
try:
# Note: we should use the checkpoint feature, new in ZODB 3.3
# Unfortunately, we still use ZODB 3.2...
# Without this feature, we cannot reliably undo the effects
# of failed requests (we try with subtransactions)
request = self._makeRequest(path, query, method, headers, request_params)
zope_response = request.response
object = request.traverse(request['PATH_INFO'].strip(),
validated_hook=validated_hook,
)
result=mapply(object, request.args, request,
call_object,1,
missing_name,
dont_publish_class,
request, bind=1,
)
if result is not zope_response: zope_response.setBody(result)
get_transaction().commit(1)
except:
try:
# Probably, we need special treatment for 'raise redirect'
if not catch_exc or err_hook is None: raise
response._setException()
# we learned from Malcolm that 'err_hook' always raises an exception
try:
zope_response = err_hook(request['PARENTS'][0], *exc_info())
except:
# Note: we do not handle "Retry" (as it is very unlikely)
zope_response.exception(*exc_info())
finally: get_transaction().abort(1)
response._setFromZope(zope_response)
--
Dieter
More information about the Zope
mailing list