Closed MainRo closed 2 years ago
Observers should never throw exceptions. We cannot call on_completed
again, and we cannot call on_error
, since it violates the contract, and what if on_error
also throws? As for RxPY, we have already notified the user code, and there's basically nothing more we can do (terminate the program?). This needs to be handled by user code, wrapping in e.g a SafeObserver
or similar.
Ref:
Thanks, This, unfortunately, confirms my understanding. My original issue was due to a bug, but I need to handle any potential exceptions being raised here gracefully.
Possibly, the most natural way in my case is to catch exceptions in each completion handler and propagate an on_error downstream. This would change a completion chain to an error chain, which is valid behavior AFAIU:
source:completion->op1:on_completed (raises an exception, chain with on_error)->op2:on_error->...->subscribe:on_error
Describe the bug If an operator raises an exception in its completion handler, then this exception is lost. This leads to stalled pipelines.
To Reproduce Steps to reproduce the behavior:
Expected behavior The pipeline should complete, or at least we need a way to catch this exception to dispose the subscription. I am not sure on how to deal with this in a generic way:
In AutoDetachObserver we could add an addition try/except block when calling self._on_completed. In the exception handler we could call the on_error handler:
This correctly propagates the error in my situation but:
Code or Screenshots
Additional context Add any other context about the problem here.