Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error during exceptions on event observer #5

Open
gnzsnz opened this issue Sep 1, 2024 · 1 comment
Open

error during exceptions on event observer #5

gnzsnz opened this issue Sep 1, 2024 · 1 comment

Comments

@gnzsnz
Copy link
Collaborator

gnzsnz commented Sep 1, 2024

when observer raises an exception and there is no error_event, logging fails

    def __call__(self, caller, *args, **kwargs):
        """Loop over all active callbacks and call them"""
        for slot in self.slots.copy():
            ref = slot.weakref
            func = slot.func

            try:
                if ref:
                    obj = ref()
                else:
                    obj = slot.obj

                result = None
                if obj is None:
                    if func:
                        result = func(*args, **kwargs)
                else:
                    if func:
                        result = func(obj, *args, **kwargs)
                    else:
                        result = obj(*args, **kwargs)

                # even though asyncio.iscoroutine() would also work here,
                # this manual hasattr() check performs better.
                if result and hasattr(result, "__await__"):
                    asyncio.ensure_future(result, loop=get_event_loop())
            except Exception as error:
                # It's not really clear in the documentation or usage that exceptions
                # get returned via an 'error_event' callback. We should make sure
                # people know this clearly so event handler callback errors are noticed.
                if len(caller.error_event):
                    caller.error_event.emit(caller, error)
                else:
>                   Event.logger.exception(
                        f"Value {args} caused exception for event {caller}"
                    )
E                   AttributeError: type object 'Event' has no attribute 'logger'

eventkit/event.py:112: AttributeError
@gnzsnz
Copy link
Collaborator Author

gnzsnz commented Sep 1, 2024

fix on 2bca019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant