Convert exception messages to strings
Exception messages are expected to be strings, but it's not always the case. Some exceptions are wrapped and passed as new exception messages, which affects some exception handlers. Finding all the occurrences may be difficult. For now, it's easier to just convert the exception messages to strings in the NovaException class. Closes-Bug: #1801713 Change-Id: Ic470791aa2b08ca9911bf70cb3cc68652d3647f2
This commit is contained in:
parent
88951ca98e
commit
fcb26b5401
|
@ -23,6 +23,7 @@ SHOULD include dedicated exception logging.
|
|||
"""
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
import webob.exc
|
||||
from webob import util as woutil
|
||||
|
@ -77,15 +78,16 @@ class NovaException(Exception):
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
if not message:
|
||||
try:
|
||||
try:
|
||||
if not message:
|
||||
message = self.msg_fmt % kwargs
|
||||
|
||||
except Exception:
|
||||
# NOTE(melwitt): This is done in a separate method so it can be
|
||||
# monkey-patched during testing to make it a hard failure.
|
||||
self._log_exception()
|
||||
message = self.msg_fmt
|
||||
else:
|
||||
message = six.text_type(message)
|
||||
except Exception:
|
||||
# NOTE(melwitt): This is done in a separate method so it can be
|
||||
# monkey-patched during testing to make it a hard failure.
|
||||
self._log_exception()
|
||||
message = self.msg_fmt
|
||||
|
||||
self.message = message
|
||||
super(NovaException, self).__init__(message)
|
||||
|
|
|
@ -153,6 +153,8 @@ class NovaExceptionTestCase(test.NoDBTestCase):
|
|||
def test_error_msg(self):
|
||||
self.assertEqual('test',
|
||||
six.text_type(exception.NovaException('test')))
|
||||
self.assertEqual('test',
|
||||
exception.NovaException(Exception('test')).message)
|
||||
|
||||
def test_default_error_msg_with_kwargs(self):
|
||||
class FakeNovaException(exception.NovaException):
|
||||
|
|
Loading…
Reference in New Issue