-
Notifications
You must be signed in to change notification settings - Fork 7.6k
2.x: Wrapping onError life cycle violations in a marker exception #5035
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
Comments
In 1.x, you got an Beyond this, I still don't see any other distinguishing factor with errors beyond lifecycle. Unfortunate that is, programmers are usually not responsible and can't do much about it (beyond perhaps using delayError flags or overloads).
Beyond these, there could be cases when some operation throws an There are a bunch of scheduling operators that may call |
Yes, wrapping "normal" errors in I agree that crashing on programming errors is good. My main gripe right now is that both code paths result in the same stack trace so it's very hard figure out if I "forgot" I notice that it isn't just me struggling with this in our code base so I worry that as more people migrate to RxJava 2.x they will run into the same problems. |
I'll prepare a PR for this then.
These errors where there in 1.x as well but were practically ignored as the default handler was a no-op handler. |
I meant struggling in the sense that it's hard to find the source of the error. Having |
See #5036. |
Closing via #5036 |
Related to my question in #5009, I've run into more situations where
onError()
might be called outside of the correct observable lifecycle (as a result of an async operation using a subject for example). David noted in #5009, "RxJava can't distinguish between wanted and unwanted errors that are raised beyond the lifecycle (or cancellation)."However, because these life cycle errors are raised using the default uncaught error exception, they are very hard to distinguish from "normal" unhandled rx errors by the developer too; they look the same and only after verifying that all errors are handled correctly in the stream you'll know for sure that an error must be related to the life cycle. Because they look and act the same, it's not possible to handle those exception in a different way if required either.
Therefore I'd like to propose to wrap errors that are caused by life cycle violations to be wrapped in an exception like
RxLifecycleException
to signal that a particular error is caused by a programming mistake related to the life cycle, as opposed to an unhandled exception resulting from the stream.Wrapping life cycle errors like that would also allow developers to choose how to handle these using the global error handler. For example: crash in debug builds, but warn only in production builds if appropriate.
This would keep the general design of not ignoring errors and would make it easier to identify life cycle related errors.
The text was updated successfully, but these errors were encountered: