Aplakka File: Supervision Strategies not working in Directory.walk(path)


I use Directory.walk(path) to traverse all subdirectories.
It works perfectly.
But some subdirectories may encounter permission issue and throw an exception:

java.io.UncheckedIOException: java.nio.file.AccessDeniedException: /full/path/name

I want to use supervision strategies(resume) so that the stream can continue the process.
But it seems with no luck. Follow is the sample code:

    val decider: Supervision.Decider = {
      case _: UncheckedIOException => Supervision.Resume
      case _                      => Supervision.Stop

    implicit val actorSystem = ActorSystem("FileIOExample")
    val actorMaterializerSettings = ActorMaterializerSettings(actorSystem).withSupervisionStrategy(decider)
    implicit val actorMaterializer = ActorMaterializer(actorMaterializerSettings)
    implicit val ec = actorSystem.dispatcher

    Directory.walk(Paths.get("/")).to {
      Sink.foreach(f =>

Do I miss something? Thanks a lot.

Supervision in akka-streams is trickier than in Actors
If you look at the note at the paragraph beginning, you’ll discover that each stage might or might not support supervision.

The point is that you need to check out if the Directory.walk stage is one of the “lucky guys”, and read the docs to learn if and how it might handle supervision

Hi @Ivano

Thank you for your question and investigation about Directory.walk. You’re right that operator doesn’t have supervision built in right now.

It is a very thin wrapper of Files.walk so you might want to take a copy to experiment with add supervision.

It would be great if you would come up with a Pull Request to improve it in Alpakka!


Well maybe @vitojeng will be more interested into that, I was just giving a hint to the current situation.

I currently have no time to dedicate, sadly.

Thank you @Ivano, very helpful!
I would take a look when I have time.

Also thanks @ennru for the explanation.