Skip to content

Commit

Permalink
changed behaviour of default_error_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
semiversus committed May 24, 2021
1 parent 7e5253c commit 42b5293
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.4.0

* changed default behavior of error_handler: now it raises an exception

## 2.3.3

* added `broqer.Timer` class and rewrite `op.Throttle` to use that class
Expand Down
3 changes: 1 addition & 2 deletions broqer/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
""" Implementing DefaultErrorHandler. Object default_error_handler is used
as global object to register a callbacks for exceptions in asynchronous
operators, """
import traceback


def _default_error_callback(exc_type, exc_value, exc_traceback):
""" Default error callback is printing traceback of the exception
"""
traceback.print_exception(exc_type, exc_value, exc_traceback)
raise exc_value.with_traceback(exc_traceback)


class DefaultErrorHandler:
Expand Down
13 changes: 10 additions & 3 deletions broqer/publisher.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
""" Implementing Publisher """
import sys
from typing import (TYPE_CHECKING, TypeVar, Type, Tuple, Callable, Optional,
overload)

from broqer import NONE, Disposable
from broqer import NONE, Disposable, default_error_handler
import broqer

if TYPE_CHECKING:
Expand Down Expand Up @@ -141,7 +142,10 @@ def notify(self, value: TValue) -> None:
"""
self._state = value
for subscriber in tuple(self._subscriptions):
subscriber.emit(value, who=self)
try:
subscriber.emit(value, who=self)
except Exception: # pylint: disable=broad-except
default_error_handler(*sys.exc_info())

def reset_state(self) -> None:
""" Resets the state. Calling this method will not trigger a
Expand All @@ -150,7 +154,10 @@ def reset_state(self) -> None:
"""
self._state = NONE
for subscriber in tuple(self._subscriptions):
subscriber.reset_state()
try:
subscriber.reset_state()
except Exception: # pylint: disable=broad-except
default_error_handler(*sys.exc_info())

@property
def subscriptions(self) -> Tuple['Subscriber', ...]:
Expand Down
17 changes: 4 additions & 13 deletions tests/test_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ def test_default(capsys):
except:
exc = sys.exc_info()

default_error_handler(*exc)

captured = capsys.readouterr()

assert captured.err.startswith('Traceback (most recent call last):')
assert 'ZeroDivisionError: division by zero' in captured.err
assert __file__ in captured.err

assert captured.out == ''
with pytest.raises(ZeroDivisionError):
default_error_handler(*exc)


def test_set_errorhandler(capsys):
Expand All @@ -44,7 +37,5 @@ def test_set_errorhandler(capsys):
# reset
default_error_handler.reset()

default_error_handler(*exc)

captured = capsys.readouterr()
assert captured.err.startswith('Traceback (most recent call last):')
with pytest.raises(ZeroDivisionError):
default_error_handler(*exc)

0 comments on commit 42b5293

Please sign in to comment.