From 2e80b297865e9c7b4251f97a95adaa6f4d0d4643 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 18 Dec 2012 09:50:56 -0500 Subject: 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 NovaException 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: Ie96261ed96bcede4a2b5ec5600cb93c15141a800 --- nova/exception.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'nova/exception.py') diff --git a/nova/exception.py b/nova/exception.py index 10349f386..b4d39bce0 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -29,11 +29,21 @@ import itertools import webob.exc +from nova.openstack.common import cfg from nova.openstack.common import excutils from nova.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'), +] + +CONF = cfg.CONF +CONF.register_opts(exc_log_opts) + class ConvertedException(webob.exc.WSGIHTTPException): def __init__(self, code=0, title="", explanation=""): @@ -137,8 +147,12 @@ class NovaException(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 CONF.fatal_exception_format_errors: + raise e + else: + # at least get the core message out if something happened + message = self.message super(NovaException, self).__init__(message) -- cgit