From 485a4c171bdcec337e5287410a3c45792a2df0fe Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 15 Dec 2016 09:03:23 -0600 Subject: [PATCH] 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: ", 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 --- shade/exc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shade/exc.py b/shade/exc.py index d548f1ad2..3ce23b901 100644 --- a/shade/exc.py +++ b/shade/exc.py @@ -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]))):