Merge "Log original dropped exception when a new exception occurs"

This commit is contained in:
Jenkins
2011-11-03 17:28:43 +00:00
committed by Gerrit Code Review
2 changed files with 16 additions and 8 deletions

View File

@@ -107,6 +107,8 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None,
# TODO(sandy): Find a way to import nova.notifier.api so we don't have # TODO(sandy): Find a way to import nova.notifier.api so we don't have
# to pass it in as a parameter. Otherwise we get a cyclic import of # to pass it in as a parameter. Otherwise we get a cyclic import of
# nova.notifier.api -> nova.utils -> nova.exception :( # nova.notifier.api -> nova.utils -> nova.exception :(
# TODO(johannes): Also, it would be nice to use
# utils.save_and_reraise_exception() without an import loop
def inner(f): def inner(f):
def wrapped(*args, **kw): def wrapped(*args, **kw):
try: try:

View File

@@ -979,21 +979,27 @@ def generate_glance_url():
@contextlib.contextmanager @contextlib.contextmanager
def original_exception_raised(): def save_and_reraise_exception():
"""Run some code, then re-raise the original exception. """Save current exception, run some code and then re-raise.
This is needed because when Eventlet switches greenthreads, it clears the In some cases the exception context can be cleared, resulting in None
exception context. This means if exception handler code blocks, we'll lose being attempted to be reraised after an exception handler is run. This
the helpful exception traceback information. can happen when eventlet switches greenthreads or when running an
exception handler, code raises and catches and exception. In both
cases the exception context will be cleared.
To work around this, we save the exception state, run handler code, and To work around this, we save the exception state, run handler code, and
then re-raise the original exception. then re-raise the original exception. If another exception occurs, the
saved exception is logged and the new exception is reraised.
""" """
type_, value, traceback = sys.exc_info() type_, value, traceback = sys.exc_info()
try: try:
yield yield
finally: except:
raise type_, value, traceback LOG.exception(_('Original exception being dropped'),
exc_info=(type_, value, traceback))
raise
raise type_, value, traceback
def make_dev_path(dev, partition=None, base='/dev'): def make_dev_path(dev, partition=None, base='/dev'):