From a363c410a0900a113293b14fef5b3d14814cc05e Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 8 Jan 2013 13:20:57 -0500 Subject: [PATCH] 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 --- cinder/exception.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cinder/exception.py b/cinder/exception.py index a857cf69e..7cb9bd993 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -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) -- 2.45.2