Get last element of stream on recover

Hey guys,

Let’s say we have any flow and during processing, an exception occurs because of an element.
Is it possible to get the element itself to handle the exception?

I’m aware of flow.mapError() to transform exceptions and also flow.recover() to map an exception to an element of the stream. Exceptions may occur also because of side effects, which are independent to the stream, but sometimes not.

Sometimes the causing element would be very interesting for handling the error. Is there any option to get the last element? Maybe a special buffer flow could handle that.

If you were able to use a specific class or trait for the signal that contained a reference to the element that caused the signal to be raised, then the partial function passed to flow.mapError could match on that type and then access the element. Would that approach solve your problem?