-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Scala
mongo-scala-driver: 4.3.1
exceptions thrown in map or flatmap for Observable are not propagated up.
take for example
val obs: Future[Unit] =
(for {
_ <- collection.insert(BsonDocument())
_ = sys.error("Boom")
} yield ()
).toFuture()
this future will never complete and lead to a timeout.
Only exceptions thrown in an Observable are propagated up. e.g. using a `raiseError` defined as such
def raiseError[A](e: Throwable) = new Observable[A] {
val delegate: Observable[Unit] = Observable[Unit](Seq(()))
override def subscribe(observer: Observer[_ >: A]): Unit =
delegate.subscribe(
new Observer[Unit] {
override def onError(throwable: Throwable): Unit =
observer.onError(throwable)override def onSubscribe(sub: Subscription): Unit =
observer.onSubscribe(sub)override def onComplete(): Unit =
() // not reachedoverride def onNext(tResult: Unit): Unit =
onError(e)
}
)
}
It would seem resolvable by changing `onNext` in MapObservable to
override def onNext(tResult: T): Unit =
try {
observer.onNext(s(tResult))
} catch {
case t: Throwable => observer.onError(f(t))
}
and FlatMapObservable similarly.
- is related to
-
JAVA-4524 Observable.map calls onComplete after onError
- Closed