From bb90b10b8bd0bd826bed0d9f4b60b6b41a07a8ef Mon Sep 17 00:00:00 2001 From: yuyafei Date: Thu, 7 Jul 2016 18:59:10 +0800 Subject: [PATCH] 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 --- ironic_lib/exception.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ironic_lib/exception.py b/ironic_lib/exception.py index e3f65a1..de4e041 100644 --- a/ironic_lib/exception.py +++ b/ironic_lib/exception.py @@ -26,6 +26,7 @@ import logging import six from oslo_config import cfg +from oslo_utils import excutils from ironic_lib.common.i18n import _ from ironic_lib.common.i18n import _LE @@ -70,18 +71,18 @@ class IronicException(Exception): try: message = self.message % kwargs - except Exception as e: - # kwargs doesn't match a variable in the message - # log the issue and the kwargs - LOG.exception(_LE('Exception in string format operation')) - for name, value in kwargs.items(): - LOG.error("%s: %s" % (name, value)) - - if CONF.ironic_lib.fatal_exception_format_errors: - raise e - else: - # at least get the core message out if something happened - message = self.message + except Exception: + with excutils.save_and_reraise_exception() as ctxt: + # kwargs doesn't match a variable in the message + # log the issue and the kwargs + prs = ', '.join('%s=%s' % pair for pair in kwargs.items()) + LOG.exception(_LE('Exception in string format operation ' + '(arguments %s)'), prs) + if not CONF.ironic_lib.fatal_exception_format_errors: + # at least get the core message out if something + # happened + message = self.message + ctxt.reraise = False super(IronicException, self).__init__(message)