Permalink
Browse files

Add _FATAL_EXCEPTION_FORMAT_ERRORS global.

Add a new global variable to control when exception format errors
are fatal. The goal is to be able to use this at test time to detect
incorrectly formatted exceptions.

Change-Id: Ia015bc27a445757cb1d574cadc35698cca0de086
  • Loading branch information...
dprince committed Jan 9, 2013
1 parent 788f6c5 commit 8507261996f3c2c12496141238f0e9707b4e57aa
Showing with 9 additions and 3 deletions.
  1. +9 −3 keystone/exception.py
View
@@ -22,6 +22,9 @@
CONF = config.CONF
LOG = logging.getLogger(__name__)
+# Tests use this to make exception message format errors fatal
+_FATAL_EXCEPTION_FORMAT_ERRORS = False
+
class Error(StandardError):
"""Base error class.
@@ -37,10 +40,13 @@ def __init__(self, message=None, **kwargs):
try:
message = self._build_message(message, **kwargs)
- except KeyError:
+ except KeyError as e:
# if you see this warning in your logs, please raise a bug report
- LOG.warning('missing expected exception kwargs (programmer error)')
- message = self.__doc__
+ if _FATAL_EXCEPTION_FORMAT_ERRORS:
+ raise e
+ else:
+ LOG.warning('missing exception kwargs (programmer error)')
+ message = self.__doc__
super(Error, self).__init__(message)

0 comments on commit 8507261

Please sign in to comment.