6

I'm building a library that is going to be used by 3rd-party. In one of my methods I return Stream[Item] that is asynchronously generated from result of paginated REST API call.

I'm using my modification of BulkPullerAsync. My code is here.

I want recipient of my stream to be able to handle errors. According to documentation I'm supposed to use custom Supervision.Decider.

val decider: Supervision.Decider = {
  case ex =>
    ex.printStackTrace()
    Supervision.Stop
}

implicit val mat = ActorMaterializer(ActorMaterializerSettings(system).withSupervisionStrategy(decider))

Unfortunately it doesn't catch exceptions thrown in my ActionPublisher. I see it handled, ActorPublisher.onError is called but it doesn't reach Supervision.Decider. It works with simple Stream provided in documentation.

Errors also don't reach actor if I use Sink.actorRef.

What should I do ? I expect that users of my Stream should not depend on nature of its implementation.

UPD: And for the sake of experiment I tried following sample

val stream = Source(0 to 5).map(100 / _)
stream.runWith(Sink.actorSubscriber(props))

In this case exception was caught by Decider.

UPD2: I tried to trick it by producing Publisher from different type of sources and then converting them back to Source expecting all errors to come to Subscriber.onError which does happen :) So apparently it's something wrong with mix ActorPublisher+Decider...

Overall I think it's inconsistent behavior. I cannot use one mechanism for handling errors in Stream.

expert
  • 29,290
  • 30
  • 110
  • 214

0 Answers0