Skip to content

Commit e58c4a7

Browse files
committed
Have undeliverable errors on subscribe() sent to plugin error handler. (#3887)
1 parent 5da378f commit e58c4a7

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/main/java/rx/Observable.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8530,18 +8530,23 @@ static <T> Subscription subscribe(Subscriber<? super T> subscriber, Observable<T
85308530
} catch (Throwable e) {
85318531
// special handling for certain Throwable/Error/Exception types
85328532
Exceptions.throwIfFatal(e);
8533-
// if an unhandled error occurs executing the onSubscribe we will propagate it
8534-
try {
8535-
subscriber.onError(hook.onSubscribeError(e));
8536-
} catch (Throwable e2) {
8537-
Exceptions.throwIfFatal(e2);
8538-
// if this happens it means the onError itself failed (perhaps an invalid function implementation)
8539-
// so we are unable to propagate the error correctly and will just throw
8540-
RuntimeException r = new RuntimeException("Error occurred attempting to subscribe [" + e.getMessage() + "] and then again while trying to pass to onError.", e2);
8541-
// TODO could the hook be the cause of the error in the on error handling.
8542-
hook.onSubscribeError(r);
8543-
// TODO why aren't we throwing the hook's return value.
8544-
throw r;
8533+
// in case the subscriber can't listen to exceptions anymore
8534+
if (subscriber.isUnsubscribed()) {
8535+
RxJavaPluginUtils.handleException(hook.onSubscribeError(e));
8536+
} else {
8537+
// if an unhandled error occurs executing the onSubscribe we will propagate it
8538+
try {
8539+
subscriber.onError(hook.onSubscribeError(e));
8540+
} catch (Throwable e2) {
8541+
Exceptions.throwIfFatal(e2);
8542+
// if this happens it means the onError itself failed (perhaps an invalid function implementation)
8543+
// so we are unable to propagate the error correctly and will just throw
8544+
RuntimeException r = new OnErrorFailedException("Error occurred attempting to subscribe [" + e.getMessage() + "] and then again while trying to pass to onError.", e2);
8545+
// TODO could the hook be the cause of the error in the on error handling.
8546+
hook.onSubscribeError(r);
8547+
// TODO why aren't we throwing the hook's return value.
8548+
throw r;
8549+
}
85458550
}
85468551
return Subscriptions.unsubscribed();
85478552
}

0 commit comments

Comments
 (0)