Skip to content

Commit

Permalink
Do not raise NEW exceptions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Sergey Vilgelm committed Jun 24, 2013
1 parent 9dd8a85 commit 41cc89a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions glance/api/v1/upload_utils.py
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions glance/common/exception.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion glance/common/rpc.py
Expand Up @@ -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") %
Expand Down

0 comments on commit 41cc89a

Please sign in to comment.