Use save_and_reraise_exception() in HeatException
Storing sys.exc_info() in a local variable in HeatException.__init__ would have caused a reference loop in cases where formatting the exception message failed. Change-Id: I29502344713e5d4da761d9277b445a6921dbd83b Related-Bug: #1626675
This commit is contained in:
parent
82b8fd8c17
commit
4d109558fe
|
@ -19,8 +19,9 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_utils import excutils
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import reraise as raise_
|
|
||||||
|
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
from heat.common.i18n import _LE
|
from heat.common.i18n import _LE
|
||||||
|
@ -58,16 +59,14 @@ class HeatException(Exception):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
try:
|
|
||||||
if self.error_code in ERROR_CODE_MAP:
|
if self.error_code in ERROR_CODE_MAP:
|
||||||
self.msg_fmt = ERROR_CODE_MAP[self.error_code]
|
self.msg_fmt = ERROR_CODE_MAP[self.error_code]
|
||||||
|
|
||||||
|
try:
|
||||||
self.message = self.msg_fmt % kwargs
|
self.message = self.msg_fmt % kwargs
|
||||||
|
|
||||||
if self.error_code:
|
|
||||||
self.message = 'HEAT-E%s %s' % (self.error_code, self.message)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
exc_info = sys.exc_info()
|
with excutils.save_and_reraise_exception(
|
||||||
|
reraise=_FATAL_EXCEPTION_FORMAT_ERRORS):
|
||||||
# kwargs doesn't match a variable in the message
|
# kwargs doesn't match a variable in the message
|
||||||
# log the issue and the kwargs
|
# log the issue and the kwargs
|
||||||
LOG.exception(_LE('Exception in string format operation'))
|
LOG.exception(_LE('Exception in string format operation'))
|
||||||
|
@ -75,8 +74,8 @@ class HeatException(Exception):
|
||||||
LOG.error(_LE("%(name)s: %(value)s"),
|
LOG.error(_LE("%(name)s: %(value)s"),
|
||||||
{'name': name, 'value': value}) # noqa
|
{'name': name, 'value': value}) # noqa
|
||||||
|
|
||||||
if _FATAL_EXCEPTION_FORMAT_ERRORS:
|
if self.error_code:
|
||||||
raise_(exc_info[0], exc_info[1], exc_info[2])
|
self.message = 'HEAT-E%s %s' % (self.error_code, self.message)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.message
|
return self.message
|
||||||
|
|
Loading…
Reference in New Issue