Commit ca8f3bcc authored by Sidnei da Silva's avatar Sidnei da Silva

- RESPONSE.handle_errors was wrongly set (to debug, should have been

  ``not debug``). Also, the check for exception constructor arguments
  didn't account for exceptions that didn't override the ``__init__``
  (which are most of them). The combination of those two problems
  caused the ``standard_error_message`` not to be called. Fixes
  https://bugs.edge.launchpad.net/zope2/+bug/372632 .
parent aa9ad517
......@@ -36,6 +36,13 @@ Features Added
Bugs Fixed
++++++++++
- RESPONSE.handle_errors was wrongly set (to debug, should have been
``not debug``). Also, the check for exception constructor arguments
didn't account for exceptions that didn't override the ``__init__``
(which are most of them). The combination of those two problems
caused the ``standard_error_message`` not to be called. Fixes
https://bugs.edge.launchpad.net/zope2/+bug/372632 .
- DocumentTemplate.DT_Raise: use new 'zExceptions.convertExceptionType'
API to allow raising non-builtin exceptions.
Fixes https://bugs.launchpad.net/zope2/+bug/372629 , which prevented
......@@ -50,7 +57,7 @@ Bugs Fixed
Bugs Fixed
++++++++++
- fixed versions.cfg in order to support zope.z2release for
- fixed versions.cfg in order to support zope.z2release for
creating a proper index structure
2.12.0a3 (2009-04-19)
......
......@@ -237,15 +237,24 @@ class Item(Base,
if not REQUEST:
REQUEST = aq_acquire(self, 'REQUEST')
handle_errors = getattr(getattr(REQUEST, 'RESPONSE', None),
handle_errors = getattr(getattr(REQUEST, 'RESPONSE', None),
'handle_errors', False)
# Can we re-raise the exception with a rendered-to-HTML
# exception value? To be able to do so, the exception
# constructor needs to be able to take more than two
# arguments (some Zope 3 exceptions can't).
ctor = getattr(getattr(error_type, '__init__', None), 'im_func', None)
can_raise = (ctor is not None and inspect.isfunction(ctor)
and len(inspect.getargspec(error_type.__init__)[0]) > 2)
ctor = getattr(error_type, '__init__', None)
if inspect.ismethoddescriptor(ctor):
# If it's a method descriptor, it means we've got a
# base ``__init__`` method that was not overriden,
# likely from the base ``Exception`` class.
can_raise = True
else:
if inspect.ismethod(ctor):
ctor = getattr(ctor, 'im_func', None)
can_raise = (
ctor is not None and inspect.isfunction(ctor)
and len(inspect.getargspec(error_type.__init__)[0]) > 2)
if not (can_raise and handle_errors):
# If we have been asked not to handle errors and we
......
......@@ -32,6 +32,35 @@ class TestSimpleItem(unittest.TestCase):
verifyClass(ISimpleItem, SimpleItem)
def test_standard_error_message_is_called(self):
from zExceptions import BadRequest
from OFS.SimpleItem import SimpleItem
# handle_errors should default to True. It is a flag used for
# functional doctests. See ZPublisher/Test.py and
# ZPublisher/Publish.py.
class REQUEST(object):
class RESPONSE(object):
handle_errors = True
class StandardErrorMessage(object):
def __init__(self):
self.kw = {}
def __call__(self, **kw):
self.kw.clear()
self.kw.update(kw)
item = SimpleItem()
item.standard_error_message = sem = StandardErrorMessage()
try:
raise BadRequest("1")
except:
item.raise_standardErrorMessage(client=item,
REQUEST=REQUEST())
self.assertEquals(sem.kw.get('error_type'), 'BadRequest')
def test_suite():
return unittest.TestSuite((
......
......@@ -194,7 +194,7 @@ def publish_module_standard(module_name,
else:
stdout=response.stdout
response.handle_errors = debug
response.handle_errors = not debug
if request is None:
request=Request(stdin, environ, response)
......
......@@ -188,7 +188,7 @@ def publish_module(module_name,
else:
stdout=response.stdout
response.handle_errors = debug
response.handle_errors = not debug
if request is None:
request=Request(stdin, environ, response)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment