Add option to make exception format errors fatal.
Adds a new fatal_exception_format_errors config option which defaults to False. This option is use to control how the base CinderException class handles errors which can occur when it formats error messages. The motivation for this change is to be able to enable exception format checking in our tests by setting fatal_exception_format_errors=True. Change-Id: I2df952558d3f30a557cbb094f8bddcc37af9b5aa
This commit is contained in:
@@ -26,10 +26,21 @@ SHOULD include dedicated exception logging.
|
||||
|
||||
import webob.exc
|
||||
|
||||
from cinder import flags
|
||||
from cinder.openstack.common import cfg
|
||||
from cinder.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
exc_log_opts = [
|
||||
cfg.BoolOpt('fatal_exception_format_errors',
|
||||
default=False,
|
||||
help='make exception message format errors fatal'),
|
||||
]
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
FLAGS.register_opts(exc_log_opts)
|
||||
|
||||
|
||||
class ConvertedException(webob.exc.WSGIHTTPException):
|
||||
def __init__(self, code=0, title="", explanation=""):
|
||||
@@ -114,8 +125,11 @@ class CinderException(Exception):
|
||||
LOG.exception(_('Exception in string format operation'))
|
||||
for name, value in kwargs.iteritems():
|
||||
LOG.error("%s: %s" % (name, value))
|
||||
# at least get the core message out if something happened
|
||||
message = self.message
|
||||
if FLAGS.fatal_exception_format_errors:
|
||||
raise e
|
||||
else:
|
||||
# at least get the core message out if something happened
|
||||
message = self.message
|
||||
|
||||
super(CinderException, self).__init__(message)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user