-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Handle undeliverable errors in rxObservable #2178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,12 +164,10 @@ private class RxObservableCoroutine<T: Any>( | |
* Such behaviour is inconsistent, leads to silent failures and we can't possibly know whether | ||
* the cause will be handled by onError (and moreover, it depends on whether a fatal exception was | ||
* thrown by subscriber or upstream). | ||
* To make behaviour consistent and least surprising, we always handle fatal exceptions | ||
* by coroutines machinery, anyway, they should not be present in regular program flow, | ||
* thus our goal here is just to expose it as soon as possible. | ||
* To make behaviour consistent and least surprising, we always deliver fatal exceptions to the | ||
* RX global exception handler. | ||
*/ | ||
subscriber.tryOnError(cause) | ||
if (!handled && cause.isFatal()) { | ||
if (!subscriber.tryOnError(cause) || (!handled && cause.isFatal())) { | ||
Comment on lines
-171
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the |
||
handleUndeliverableException(cause, context) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,10 @@ | |
|
||
package kotlinx.coroutines.rx2 | ||
|
||
import io.reactivex.* | ||
import io.reactivex.plugins.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.CancellationException | ||
import org.junit.* | ||
import org.junit.Test | ||
import java.util.concurrent.* | ||
import kotlin.test.* | ||
|
||
class ObservableTest : TestBase() { | ||
|
@@ -137,28 +134,4 @@ class ObservableTest : TestBase() { | |
expect(4) | ||
} | ||
} | ||
|
||
@Test | ||
fun testExceptionAfterCancellation() { | ||
// Test that no exceptions were reported to the global EH (it will fail the test if so) | ||
val handler = { e: Throwable -> | ||
assertFalse(e is CancellationException) | ||
} | ||
withExceptionHandler(handler) { | ||
RxJavaPlugins.setErrorHandler { | ||
require(it !is CancellationException) | ||
} | ||
Observable | ||
.interval(1, TimeUnit.MILLISECONDS) | ||
.take(1000) | ||
.switchMapSingle { | ||
rxSingle { | ||
timeBomb().await() | ||
} | ||
} | ||
.blockingSubscribe({}, {}) | ||
} | ||
} | ||
Comment on lines
-141
to
-161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test seems to have been taken from the issue reported at #252. However it's complicated and not well implemented (I originally tried to improve it in commit 58ad0cd). Also, it was actually testing |
||
|
||
private fun timeBomb() = Single.timer(1, TimeUnit.MILLISECONDS).doOnSuccess { throw TestException() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was changed in #1638, but seems like the comment was not updated.