Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions matrix/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ async def _on_error(self, error: Exception) -> None:
await handler(error)
return

if self._fallback_error_handler:
await self._fallback_error_handler(error)
return

await self._dispatch("on_error", error)

async def on_command(self, _ctx: Context) -> None:
Expand Down
10 changes: 5 additions & 5 deletions matrix/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def __init__(self, name: str, prefix: Optional[str] = None):

self._event_handlers: Dict[Type[Event], List[Callback]] = defaultdict(list)
self._hook_handlers: Dict[str, List[Callback]] = defaultdict(list)
self._fallback_error_handler: Optional[ErrorCallback] = None
self._error_handlers: Dict[type[Exception], ErrorCallback] = {}
self._command_error_handlers: Dict[type[Exception], CommandErrorCallback] = {}

Expand Down Expand Up @@ -378,14 +377,15 @@ async def on_any_error(error):
```
"""

if not exception:
exception = Exception

def wrapper(func: ErrorCallback) -> ErrorCallback:
if not inspect.iscoroutinefunction(func):
raise TypeError("Error handlers must be coroutines")

if exception:
self._error_handlers[exception] = func
else:
self._fallback_error_handler = func
self._error_handlers[exception] = func

logger.debug(
"registered error handler '%s' on %s",
func.__name__,
Expand Down
4 changes: 1 addition & 3 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ async def custom_error_handler(e):
nonlocal called
called = True

await bot._fallback_error_handler(Exception("test error"))
await bot.on_error(Exception("test error"))

await bot._on_error(Exception("test error"))
assert called, "Fallback error handler was not called"


Expand Down
10 changes: 0 additions & 10 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,6 @@ async def on_value_error(error):
assert registry._error_handlers[ValueError] is on_value_error


def test_register_generic_error_handler__expect_fallback_error_handler_set(
registry: Registry,
):
@registry.error()
async def on_any_error(error):
pass

assert registry._fallback_error_handler is on_any_error


def test_register_error_handler_with_non_coroutine__expect_type_error(
registry: Registry,
):
Expand Down
Loading