Skip to content

Commit

Permalink
Merge pull request #7 from migibert/exception_fix
Browse files Browse the repository at this point in the history
Exception raised from circuited function should be propagated
  • Loading branch information
etimberg authored May 22, 2021
2 parents 6e41649 + a587e05 commit 8662748
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pycircuitbreaker/pycircuitbreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def call(self, func, *args, **kwargs):
result = None

try:
result = func(*args, *kwargs)
result = func(*args, **kwargs)
except Exception as ex:
if not self._exception_whitelisted(ex) and self._exception_blacklisted(ex):
self._handle_error(ex)
raise
raise

if self._detect_error is not None and self._detect_error(result):
self._handle_error(result)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_breaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def test_exception_whitelist(error_func):
breaker = CircuitBreaker(
error_threshold=1, exception_whitelist=[IOError], recovery_timeout=1
)
breaker.call(error_func)
with pytest.raises(IOError):
breaker.call(error_func)

assert breaker.state == CircuitBreakerState.CLOSED

Expand All @@ -112,7 +113,8 @@ def test_exception_whitelist_supports_inheritance(error_func):
breaker = CircuitBreaker(
error_threshold=1, exception_whitelist=[Exception], recovery_timeout=1
)
breaker.call(error_func)
with pytest.raises(IOError):
breaker.call(error_func)

assert breaker.state == CircuitBreakerState.CLOSED

Expand All @@ -122,7 +124,8 @@ def test_exception_blacklist_filters_errors(error_func):
breaker = CircuitBreaker(
error_threshold=1, exception_blacklist=[ValueError], recovery_timeout=1
)
breaker.call(error_func)
with pytest.raises(IOError):
breaker.call(error_func)

assert breaker.state == CircuitBreakerState.CLOSED

Expand Down

0 comments on commit 8662748

Please sign in to comment.