Make re-raising of client exceptions safer
Given that we are passing the exception value as a parameter to ignore_not_found() and its ilk, it is very unexpected that they ignore this parameter and instead raise whatever the last exception was. Guard against this by checking that we really are re-raising the same exception, and fall back to re-raising the correct exception with a new stack trace if not. Change-Id: I18a86569a9ba4ee81d943d496349a585dad74ef6 Related-Bug: #1495714
This commit is contained in:
parent
412b3f59d0
commit
ba06cb4016
@ -174,16 +174,22 @@ class ClientPlugin(object):
|
|||||||
def ignore_not_found(self, ex):
|
def ignore_not_found(self, ex):
|
||||||
"""Raises the exception unless it is a not-found."""
|
"""Raises the exception unless it is a not-found."""
|
||||||
if not self.is_not_found(ex):
|
if not self.is_not_found(ex):
|
||||||
exc_info = sys.exc_info()
|
exc_type, exc_val, traceback = sys.exc_info()
|
||||||
six.reraise(*exc_info)
|
if exc_val is ex:
|
||||||
|
six.reraise(exc_type, exc_val, traceback)
|
||||||
|
else:
|
||||||
|
raise ex
|
||||||
|
|
||||||
def ignore_conflict_and_not_found(self, ex):
|
def ignore_conflict_and_not_found(self, ex):
|
||||||
"""Raises the exception unless it is a conflict or not-found."""
|
"""Raises the exception unless it is a conflict or not-found."""
|
||||||
if self.is_conflict(ex) or self.is_not_found(ex):
|
if self.is_conflict(ex) or self.is_not_found(ex):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
exc_info = sys.exc_info()
|
exc_type, exc_val, traceback = sys.exc_info()
|
||||||
six.reraise(*exc_info)
|
if exc_val is ex:
|
||||||
|
six.reraise(exc_type, exc_val, traceback)
|
||||||
|
else:
|
||||||
|
raise ex
|
||||||
|
|
||||||
def _get_client_args(self,
|
def _get_client_args(self,
|
||||||
service_name,
|
service_name,
|
||||||
|
Loading…
Reference in New Issue
Block a user