Refactor MagnumException to reduce complexity

Reduce cyclomatic complexity of MagnumException to below 10. Remove
exception handling and optimise the logging when the kwargs does not
match the message.

Change-Id: I4fd6ba96be9dff485cdd8bde9750f2d584c1ec63
Closes-Bug: #1501331
This commit is contained in:
Tom Cammann 2015-10-16 13:28:05 +01:00
parent 82003a56e5
commit ee52fbbcba
2 changed files with 5 additions and 10 deletions

View File

@ -193,11 +193,8 @@ class MagnumException(Exception):
def __init__(self, message=None, **kwargs):
self.kwargs = kwargs
if 'code' not in self.kwargs:
try:
self.kwargs['code'] = self.code
except AttributeError:
pass
if 'code' not in self.kwargs and hasattr(self, 'code'):
self.kwargs['code'] = self.code
if message:
self.message = message
@ -207,10 +204,8 @@ class MagnumException(Exception):
except Exception as e:
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(_LE('Exception in string format operation'))
for name, value in kwargs.items():
LOG.error(_LE("%(name)s: %(value)s") %
{'name': name, 'value': value})
LOG.exception(_LE('Exception in string format operation, '
'kwargs: %s') % kwargs)
try:
if CONF.fatal_exception_format_errors:
raise e

View File

@ -26,7 +26,7 @@ deps =
[testenv:pep8]
commands =
doc8 -e .rst specs/ doc/source/ contrib/ CONTRIBUTING.rst HACKING.rst README.rst
flake8 --max-complexity 11 {posargs}
flake8 --max-complexity 10 {posargs}
[testenv:venv]
commands = {posargs}