Browse Source

Merge "Update ExpectedException handling"

changes/78/73278/1
Jenkins 7 years ago
committed by Gerrit Code Review
parent
commit
70dbe6a7cc
3 changed files with 27 additions and 7 deletions
  1. +6
    -2
      oslo/messaging/_executors/base.py
  2. +8
    -5
      oslo/messaging/rpc/server.py
  3. +13
    -0
      tests/test_expected_exceptions.py

+ 6
- 2
oslo/messaging/_executors/base.py View File

@ -38,12 +38,16 @@ class ExecutorBase(object):
_LOG.debug('Expected exception during message handling (%s)' %
e.exc_info[1])
incoming.reply(failure=e.exc_info, log_failure=False)
except Exception:
except Exception as e:
# sys.exc_info() is deleted by LOG.exception().
exc_info = sys.exc_info()
_LOG.error('Exception during message handling',
_LOG.error('Exception during message handling: %s', e,
exc_info=exc_info)
incoming.reply(failure=exc_info)
# NOTE(dhellmann): Remove circular object reference
# between the current stack frame and the traceback in
# exc_info.
del exc_info
@abc.abstractmethod
def start(self):


+ 8
- 5
oslo/messaging/rpc/server.py View File

@ -151,10 +151,13 @@ def expected_exceptions(*exceptions):
def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
if type(e) in exceptions:
raise ExpectedException()
else:
raise
# Take advantage of the fact that we can catch
# multiple exception types using a tuple of
# exception classes, with subclass detection
# for free. Any exception that is not in or
# derived from the args passed to us will be
# ignored and thrown as normal.
except exceptions:
raise ExpectedException()
return inner
return outer

+ 13
- 0
tests/test_expected_exceptions.py View File

@ -43,6 +43,19 @@ class TestExpectedExceptions(test_utils.BaseTestCase):
self.assertRaises(messaging.ExpectedException, naughty)
def test_decorator_expected_subclass(self):
class FooException(Exception):
pass
class BarException(FooException):
pass
@messaging.expected_exceptions(FooException)
def naughty():
raise BarException()
self.assertRaises(messaging.ExpectedException, naughty)
def test_decorator_unexpected(self):
class FooException(Exception):
pass


Loading…
Cancel
Save