Example #1
0
    async def _invoke_callback(self, callback: event_manager.CallbackT[
        event_manager.EventT_inv], event: event_manager.EventT_inv) -> None:
        try:
            await callback(event)
        except Exception as ex:
            # Skip the first frame in logs, we don't care for it.
            trio = type(
                ex
            ), ex, ex.__traceback__.tb_next if ex.__traceback__ is not None else None

            if base_events.is_no_recursive_throw_event(event):
                _LOGGER.error(
                    "an exception occurred handling an event (%s), but it has been ignored",
                    type(event).__name__,
                    exc_info=trio,
                )
            else:
                exception_event = base_events.ExceptionEvent(
                    exception=ex,
                    failed_event=event,
                    failed_callback=callback,
                )

                log = _LOGGER.debug if self.get_listeners(
                    type(exception_event), polymorphic=True) else _LOGGER.error
                log("an exception occurred handling an event (%s)",
                    type(event).__name__,
                    exc_info=trio)
                await self.dispatch(exception_event)
Example #2
0
def test_inherited_is_no_recursive_throw_event():
    assert base_events.is_no_recursive_throw_event(DummyPresenceDerivedEvent)
    assert not base_events.is_no_recursive_throw_event(DummyGuildDerivedEvent)
Example #3
0
def test_is_no_recursive_throw_event_marked():
    assert base_events.is_no_recursive_throw_event(DummyPresenceEvent)
    assert base_events.is_no_recursive_throw_event(ErrorEvent)
    assert not base_events.is_no_recursive_throw_event(DummyGuildEvent)
    assert not base_events.is_no_recursive_throw_event(DummyGuildDerivedEvent)