From dc99baa33648820b93c90c15bd3562284e8ce4a9 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 30 Jan 2013 11:15:10 -0500 Subject: Add _FATAL_EXCEPTION_FORMAT_ERRORS global. Add a new global variable to control when exception format errors are fatal. Also, updates the Oslo test base class to enable fatal exception format errors. The motivation for this change is to give projects that use openstack common a hook to enable exception format checking when testing. Change-Id: Id8f4a0946b1614c8e987976b79069532a2e8608f --- openstack/common/exception.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'openstack/common') diff --git a/openstack/common/exception.py b/openstack/common/exception.py index fa06d6a..4a7c72b 100644 --- a/openstack/common/exception.py +++ b/openstack/common/exception.py @@ -23,6 +23,8 @@ import logging from openstack.common.gettextutils import _ +_FATAL_EXCEPTION_FORMAT_ERRORS = False + class Error(Exception): def __init__(self, message=None): @@ -121,9 +123,12 @@ class OpenstackException(Exception): try: self._error_string = self.message % kwargs - except Exception: - # at least get the core message out if something happened - self._error_string = self.message + except Exception as e: + if _FATAL_EXCEPTION_FORMAT_ERRORS: + raise e + else: + # at least get the core message out if something happened + self._error_string = self.message def __str__(self): return self._error_string -- cgit