From: Zane Bitter Date: Fri, 7 Dec 2012 11:22:53 +0000 (+0100) Subject: Get rid of naked except: clauses X-Git-Tag: 2014.1~1117 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ab22396cb3a5b317b58cca8938e1d06baeca2edb;p=openstack-build%2Fheat-build.git Get rid of naked except: clauses The only time it is legitimate to catch all exceptions is when the exception is rethrown. Change-Id: If72243d7a2c73b42de01d2a59514ead76c20d034 Signed-off-by: Zane Bitter --- diff --git a/heat/client.py b/heat/client.py index ea25cdf1..1d76a7f4 100644 --- a/heat/client.py +++ b/heat/client.py @@ -81,7 +81,7 @@ class V1Client(base_client.BaseClient): try: result = self.stack_request("DescribeStackResources", "GET", **parameters) - except: + except Exception: logger.debug("Failed to lookup resource details with key %s:%s" % (lookup_key, lookup_value)) else: diff --git a/heat/common/auth.py b/heat/common/auth.py index 52811cdf..b4eb3892 100644 --- a/heat/common/auth.py +++ b/heat/common/auth.py @@ -241,7 +241,7 @@ class KeystoneStrategy(BaseStrategy): try: body = json.loads(resp_body) msg = body['error']['message'] - except: + except (ValueError, KeyError): msg = resp_body raise exception.KeystoneError(resp.status, msg) diff --git a/heat/common/context.py b/heat/common/context.py index 70f3f7ec..a135755d 100644 --- a/heat/common/context.py +++ b/heat/common/context.py @@ -188,7 +188,7 @@ class ContextMiddleware(wsgi.Middleware): tenant_id = headers.get('X-Tenant-Id') auth_url = headers.get('X-Auth-Url') roles = headers.get('X-Roles') - except: + except Exception: raise exception.NotAuthenticated() req.context = self.make_context(auth_token=token, diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index 8f896287..53813e55 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -482,7 +482,7 @@ class XMLResponseSerializer(object): # otherwise quotes get mangled and json.loads breaks try: subelement.text = json.dumps(value) - except: + except TypeError: subelement.text = str(value) else: self.object_to_element(value, subelement) @@ -583,7 +583,7 @@ class Resource(object): try: err_body = action_result.get_unserialized_body() serializer.default(action_result, err_body) - except: + except Exception: logging.warning("Unable to serialize exception response") return action_result