From 41cc89afa8ed7dda76eed5669ae1306a131bbbfc Mon Sep 17 00:00:00 2001 From: Sergey Vilgelm Date: Mon, 24 Jun 2013 15:32:14 +0400 Subject: [PATCH] Do not raise NEW exceptions Raising NEW exception is bad practice, because we lose TraceBack. So all places like: except SomeException as e: raise e should be replaced by except SomeException: raise If we are doing some other actions before reraising we should store information about exception then do all actions and then reraise it. This is caused by eventlet bug. It lost information about exception if it switch threads. fixes bug 1191730 Change-Id: I047e355607318bf9fa6208c2b174b7cc394297f0 --- glance/api/v1/upload_utils.py | 9 +++++---- glance/common/exception.py | 4 ++-- glance/common/rpc.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/glance/api/v1/upload_utils.py b/glance/api/v1/upload_utils.py index 485d0101d4..7d85ca17f3 100644 --- a/glance/api/v1/upload_utils.py +++ b/glance/api/v1/upload_utils.py @@ -19,6 +19,7 @@ import webob.exc from glance.common import exception +from glance.openstack.common import excutils from glance.common import utils import glance.openstack.common.log as logging import glance.registry.client.v1.api as registry @@ -166,14 +167,14 @@ def _kill_mismatched(image_meta, attr, actual): request=req, content_type='text/plain') - except webob.exc.HTTPError as e: - LOG.exception(_("Received HTTP error while uploading image.")) - safe_kill(req, image_id) + except webob.exc.HTTPError: #NOTE(bcwaldon): Ideally, we would just call 'raise' here, # but something in the above function calls is affecting the # exception context and we must explicitly re-raise the # caught exception. - raise e + with excutils.save_and_reraise_exception(): + LOG.exception(_("Received HTTP error while uploading image.")) + safe_kill(req, image_id) except Exception as e: msg = _("Failed to upload image") diff --git a/glance/common/exception.py b/glance/common/exception.py index 6648bc088e..ccfcec03d4 100644 --- a/glance/common/exception.py +++ b/glance/common/exception.py @@ -43,9 +43,9 @@ def __init__(self, message=None, *args, **kwargs): message = self.message try: message = message % kwargs - except Exception as e: + except Exception: if _FATAL_EXCEPTION_FORMAT_ERRORS: - raise e + raise else: # at least get the core message out if something happened pass diff --git a/glance/common/rpc.py b/glance/common/rpc.py index ec87c8ffc3..44a449d5f6 100644 --- a/glance/common/rpc.py +++ b/glance/common/rpc.py @@ -151,7 +151,7 @@ def validate(cmd): result = method(req.context, **kwargs) except Exception as e: if self.raise_exc: - raise e + raise cls, val = e.__class__, str(e) msg = (_("RPC Call Error: %(val)s\n%(tb)s") %