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?

Thanks for sharing this amazing article this is useful.

Yes, this approach has solved my problem.

But, Im still facing this issue, can you also help me it.

Put a `sliding(2,1) before it

Can we capture the causing element when exceptions arise in a flow for better error handling? Familiar with mapError() and recover(), but need to retain element context. Options for this?