Questions about error handling in Flows

I have 2 questions with regard to error handling in flows:

  1. In streams error handling it says I can use the supervision method Resume on a piece of a stream, but that the element that failed will be dropped. Is there a way to not drop the element? Say for example I have a flow or sink that uploads some data, and the upload failed, I’d like to retry uploading that data instead of letting the stream continue on without uploading it. Do i just need to implement a custom flow/sink that keeps the last received item in case of a resume or something?

  2. In a flow composed of multiple little flows, would an error exception from one of the sub flows propagate to the composed flow object? So for example, could I set error handling for the composed flow to resume should a specific error happen in one of its subflows, retrying an element for that pipeline?

It better to avoid the errors all together.

So if you expect an exception wrap it to a try (or either) and use that on the output. In that case you can mark the things whose went to error.
(for ex.: .map(elem => Try(maybeThrowUp(elem)).toEither.left.map(err => (elem, err)) )

For the first: Don’t do that at akka level, do that at application logic level! mark the “not so successful” data and try it again with a cycle or log down somewhere or whatever. (!be careful with cycles!)

For the second: I wouldn’t do that too. Do proper exception free error handling wherever you can!

  1. If a stage fails, e.g. because of an exception or a failed Future in case of mapAsync, then the element is dropped when using Resume or the stream is completed when using Stop which is the default. But if you know that your operations could go wrong, why not code accordingly? E.g. if you want to upload something via HTTP you will most probabaly get back a Future from that and you could use recover or recoverWith to retry or such.

  2. Failure will propagate through the whole graph. Having said that, you can fine tune supervision per composite, e.g. use Stop for some part and Resume for others, via Attributes.

Ok, so just have the custom flows/composite flows handle the exceptions internally and retry on their own. I’ll do that.