diff --git a/tobiko/common/_exception.py b/tobiko/common/_exception.py index c4dbaf44f..717b11a83 100644 --- a/tobiko/common/_exception.py +++ b/tobiko/common/_exception.py @@ -92,12 +92,12 @@ class ExceptionInfo(collections.namedtuple('ExceptionInfo', def __enter__(self): return self + def __bool__(self): + return self.type is not None + def __exit__(self, _type, _value, _traceback): if self.reraise_on_exit: - if _type is not None: - LOG.exception("Exception occurred while handling %s(%s) " - "exception.", self.type, self.value) - self.reraise() + self.reraise() def reraise(self): if self.type is not None: diff --git a/tobiko/common/_retry.py b/tobiko/common/_retry.py index e04ef941a..525b6133a 100644 --- a/tobiko/common/_retry.py +++ b/tobiko/common/_retry.py @@ -80,9 +80,9 @@ class RetryAttempt(object): return max(0, self.count - self.number) def check_count_left(self) -> _time.Seconds: - with _exception.exc_info(): - if self.count_left == 0: - raise RetryCountLimitError(attempt=self) + if self.count_left == 0: + _exception.exc_info().reraise() + raise RetryCountLimitError(attempt=self) return self.count_left @property @@ -93,9 +93,9 @@ class RetryAttempt(object): return max(0., self.timeout - self.elapsed_time) def check_time_left(self) -> _time.Seconds: - with _exception.exc_info(): - if self.time_left == 0.: - raise RetryTimeLimitError(attempt=self) + if self.time_left == 0.: + _exception.exc_info().reraise() + raise RetryTimeLimitError(attempt=self) return self.time_left def check_limits(self):