Closed jfhbrook closed 12 months ago
I realized that there are actually ways to make this work - that's currently implemented. Keeping this open as a draft, cause I'm not totally happy with the implementation.
As mentioned in #102, I've convinced myself this is a bad idea. C'est la vie.
This PR creates a new error called an
UnhandledError
, which wraps errors going through pyee's internal error handling code. This error has additional context properties:__args__
- the args the raising handler was called with__kwargs__
- the kwargs the raising handler was called withMaking this work is a bit of a challenge. The interface for the
error
event handler (Callable[[Any], Any]
) doesn't allow for passing extra args and kwargs, so I can't attach them to arbitrary error events. The best I can do is manually wrap raised exceptions in anUnhandledError
in_call_handlers
implementations. The upshot is that this is doable for exceptions raised in asyncio, trio and executors, but not in the base EventEmitter. Twisted also has some challenges, because of the way it sends failures through the "failure" event.The twisted event emitter could be refactored to better support this context, but the base EventEmitter is DOA as far as that goes. This is probably OK, since the base EventEmitter has extremely naive error handling as compared to the other subclasses.
Now that I'm not entirely happy with this implementation:
Tests are passing, though the executor tests could use better coverage.
See also #142, which removes deprecated APIs and introduces a
PyeeError
- this PR is structured based on the assumption that this change goes through.This is intended to close #102.