Stop double-reporting extra_data in exceptions

We append extra_data to the args we send to Exception, but we also
append extra_data to the str output. Thing is - Exception already does
that with all the args - so we wind up with something like:

shade.exc.OpenStackCloudException: ("Image creation failed: <type
'exceptions.OSError'>", Munch({u'status': u'failure'...)) (Extra:
Munch({u'status': u'failure'...)

Also - the Munch output isn't terribly useful in the exception, so go
ahead and dict-ify it if we've passed a munch to extra_data.

Change-Id: Ie3271093fba0ac6f074e1cfd4e6a79455dc82be4
This commit is contained in:
Monty Taylor 2016-12-15 09:03:23 -06:00
parent 916ba38123
commit 485a4c171b
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594

View File

@ -14,6 +14,7 @@
import sys
import munch
from requests import exceptions as _rex
from shade import _log
@ -26,7 +27,9 @@ class OpenStackCloudException(Exception):
def __init__(self, message, extra_data=None, **kwargs):
args = [message]
if extra_data:
args.append(extra_data)
if isinstance(extra_data, munch.Munch):
extra_data = extra_data.toDict()
args.append("Extra: {0}".format(str(extra_data)))
super(OpenStackCloudException, self).__init__(*args, **kwargs)
self.extra_data = extra_data
self.inner_exception = sys.exc_info()
@ -40,8 +43,6 @@ class OpenStackCloudException(Exception):
def __str__(self):
message = Exception.__str__(self)
if self.extra_data is not None:
message = "%s (Extra: %s)" % (message, self.extra_data)
if (self.inner_exception and self.inner_exception[1]
and not self.orig_message.endswith(
str(self.inner_exception[1]))):