Correct reraising of exception

When an exception was caught and rethrown, it should call 'raise'
without any arguments because it shows the place where an exception
occured initially instead of place where the exception re-raised.

Change-Id: I112eeea489470bca34b588bd862500d615c84e67
This commit is contained in:
yuyafei 2016-07-07 18:59:10 +08:00 committed by Sam Betts
parent 5ca6f2c9a2
commit bb90b10b8b
1 changed files with 13 additions and 12 deletions

View File

@ -26,6 +26,7 @@ import logging
import six import six
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import excutils
from ironic_lib.common.i18n import _ from ironic_lib.common.i18n import _
from ironic_lib.common.i18n import _LE from ironic_lib.common.i18n import _LE
@ -70,18 +71,18 @@ class IronicException(Exception):
try: try:
message = self.message % kwargs message = self.message % kwargs
except Exception as e: except Exception:
# kwargs doesn't match a variable in the message with excutils.save_and_reraise_exception() as ctxt:
# log the issue and the kwargs # kwargs doesn't match a variable in the message
LOG.exception(_LE('Exception in string format operation')) # log the issue and the kwargs
for name, value in kwargs.items(): prs = ', '.join('%s=%s' % pair for pair in kwargs.items())
LOG.error("%s: %s" % (name, value)) LOG.exception(_LE('Exception in string format operation '
'(arguments %s)'), prs)
if CONF.ironic_lib.fatal_exception_format_errors: if not CONF.ironic_lib.fatal_exception_format_errors:
raise e # at least get the core message out if something
else: # happened
# at least get the core message out if something happened message = self.message
message = self.message ctxt.reraise = False
super(IronicException, self).__init__(message) super(IronicException, self).__init__(message)