jfhbrook/pyee

error events via twisted are emitting Failures, not Exceptions

Closed this issue · 5 comments

Maybe the answer is to "unpack" the failure? Or maybe I should have an alternate event for Failures ?

Proposal: Make a new 'failure' event. When twisted is uninstalled, listeners on "failure" will raise an Exception when added. Otherwise:

  • When an error event is emitted with an error object and there are no handlers for the failure event, pass the error directly to the handler
  • When an error event is emitted with an error object and there are handlers for the failure event, the handlers for 'failure' are ran instead, with the exception wrapped in a Failure
  • When a handled Deferred enters an error state, and there are no handlers for the failure event, convert to an exception and pass to the 'error' event
  • When a handled Deferred enters an error state, and there are handlers for the failure event, pass that Failure to the failure event
  • If a 'failure' handler raises an exception, emit that failure to the error event

Oh man, this is getting complicated. This will also require a revamp of the docs, for sure.

Alternate approach: Write an EventEmitter base class which is synchronous. Write async EventEmitter subclasses to separately cover the use cases of asyncio async/await, twisted async/await and twisted/Deferreds. Rip out the duck typing and progressive enhancement code, depending on the user to import things that make sense.

Optionally add EventEmitter subclasses which wrap threaded use as well.

Fixed via #46