exception.py (ec2-api-14.0.1) | : | exception.py (ec2-api-15.0.0) | ||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
# limitations under the License. | # limitations under the License. | |||
"""ec2api base exception handling. | """ec2api base exception handling. | |||
Includes decorator for re-raising ec2api-type exceptions. | Includes decorator for re-raising ec2api-type exceptions. | |||
SHOULD include dedicated exception logging. | SHOULD include dedicated exception logging. | |||
""" | """ | |||
import sys | ||||
from oslo_config import cfg | from oslo_config import cfg | |||
from oslo_log import log as logging | from oslo_log import log as logging | |||
import six | ||||
from ec2api.i18n import _ | from ec2api.i18n import _ | |||
LOG = logging.getLogger(__name__) | LOG = logging.getLogger(__name__) | |||
exc_log_opts = [ | exc_log_opts = [ | |||
cfg.BoolOpt('fatal_exception_format_errors', | cfg.BoolOpt('fatal_exception_format_errors', | |||
default=False, | default=False, | |||
help='Make exception message format errors fatal'), | help='Make exception message format errors fatal'), | |||
] | ] | |||
skipping to change at line 57 | skipping to change at line 54 | |||
with the keyword arguments provided to the constructor. | with the keyword arguments provided to the constructor. | |||
""" | """ | |||
msg_fmt = _('An unknown exception occurred.') | msg_fmt = _('An unknown exception occurred.') | |||
def __init__(self, message=None, **kwargs): | def __init__(self, message=None, **kwargs): | |||
self.kwargs = kwargs | self.kwargs = kwargs | |||
if not message: | if not message: | |||
try: | try: | |||
message = self.msg_fmt % kwargs | message = self.msg_fmt % kwargs | |||
except Exception: | except Exception as e: | |||
exc_info = sys.exc_info() | ||||
# 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('Exception in string format operation for ' | LOG.exception('Exception in string format operation for ' | |||
'%s exception', self.__class__.__name__) | '%s exception', self.__class__.__name__) | |||
for name, value in kwargs.items(): | for name, value in kwargs.items(): | |||
LOG.error('%s: %s' % (name, value)) | LOG.error('%s: %s' % (name, value)) | |||
if CONF.fatal_exception_format_errors: | if CONF.fatal_exception_format_errors: | |||
six.reraise(*exc_info) | raise e | |||
else: | else: | |||
# at least get the core message out if something happened | # at least get the core message out if something happened | |||
message = self.msg_fmt | message = self.msg_fmt | |||
elif not isinstance(message, six.string_types): | elif not isinstance(message, str): | |||
LOG.error("Message '%(msg)s' for %(ex)s exception is not " | LOG.error("Message '%(msg)s' for %(ex)s exception is not " | |||
"a string", | "a string", | |||
{'msg': message, 'ex': self.__class__.__name__}) | {'msg': message, 'ex': self.__class__.__name__}) | |||
if CONF.fatal_exception_format_errors: | if CONF.fatal_exception_format_errors: | |||
raise TypeError(_('Invalid exception message format')) | raise TypeError(_('Invalid exception message format')) | |||
else: | else: | |||
message = self.msg_fmt | message = self.msg_fmt | |||
super(EC2APIException, self).__init__(message) | super(EC2APIException, self).__init__(message) | |||
End of changes. 5 change blocks. | ||||
7 lines changed or deleted | 3 lines changed or added |