Why is there no GraphStage in akka streams that can give me a failed element along with throwable?

Let’s say for example we have such a stream

Source(1 to 10)
  .map(x ⇒ if (x % 2 == 0) throw new RuntimeException("test error"))
  .mapError {
    case NonFatal(ex) ⇒
      // do something with the failed element 2
      ex.printStackTrace()
      ex
  }

The question is why not mapError give me element ‘2’ along with the ‘RuntimeException’ ?

What would you do if the types of the map were not Int to Int, but for example Int to String?

In case where map is from int to string, we want to know the input ints for which mapping to string failed. With all such failed ints we want do some side effecting like calling a function of type “(int, throwable) => unit”

Here you use two separate stages, map and mapError and the could have been more inbetween. My point is that there is no way to propagate the Int dowstream to mapError.

If you need this control you should use ordinary try-catch inside the map.