Skip to content

Commit

Permalink
- Exceptions during publishing are now re-raised when in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Apr 26, 2019
1 parent 54e18a1 commit 4ce9be5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Features
Other changes
+++++++++++++

- Exceptions during publishing are now re-raised when in debug mode
(`#562 <https://github.com/zopefoundation/Zope/issues/562>`_)

- Remove hardcoded list of factories that don't want an add dialog
(`#540 <https://github.com/zopefoundation/Zope/issues/540>`_)

Expand Down
3 changes: 2 additions & 1 deletion src/ZPublisher/WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def transaction_pubevents(request, response, tm=transaction.manager):
try:
# Raise exception from app if handle-errors is False
# (set by zope.testbrowser in some cases)
if request.environ.get('x-wsgiorg.throw_errors', False):
if request.environ.get('x-wsgiorg.throw_errors', False) or \
response.debug_mode:
reraise(*exc_info)

# Handle exception view
Expand Down
24 changes: 24 additions & 0 deletions src/ZPublisher/tests/test_WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,30 @@ def testHandleErrorsFalseBypassesExceptionResponse(self):
with self.assertRaises(Unauthorized):
self._callFUT(environ, start_response, _publish)

def testDebugModeBypassesExceptionResponse(self):
from zExceptions import BadRequest

# Register an exception view for BadRequest
registerExceptionView(IException)
environ = self._makeEnviron()
start_response = DummyCallable()
_publish = DummyCallable()
_publish._raise = BadRequest('debugbypass')

# Responses will always have debug_mode set
def response_factory(stdout, stderr):
response = DummyResponse()
response.debug_mode = True
return response

# With debug_mode, the exception view is not called.
with self.assertRaises(BadRequest):
self._callFUT(environ, start_response, _publish,
_response_factory=response_factory)

# Clean up view registration
unregisterExceptionView(IException)


class ExcViewCreatedTests(ZopeTestCase):

Expand Down

0 comments on commit 4ce9be5

Please sign in to comment.