-
-
Notifications
You must be signed in to change notification settings - Fork 622
Open
Labels
Description
fs2 version: "3.12.2"
import cats.effect.IO
import cats.effect.IOApp
import fs2.Stream
import fs2.io.file.Files
import fs2.io.file.Path
object FilesBugApp extends IOApp.Simple {
def run: IO[Unit] = {
val bytes: Stream[IO, Byte] = Stream.raiseError[IO](new RuntimeException)
bytes.through(Files[IO].writeAll(Path("should-not-be-created"))).compile.drain
}
}
I expect the file not to be created. However, the file is created. This bug also breaks the logic of saving the last file in Stream context. Below is a pseudo-scala description of bug:
val last = Files[F].list("directory").compile.toList.map(_.max)
val saveNow = F.now.flatMap(now => Files[F].writeAll(Path(s"$directory/$now"))))
Stream.eval(last).flatMap(read).map(...).through(saveNow).compile.drain
Here, last always equals to saveNow file. However, if one shifts into F context by removing the Stream.eval the code works as expected.
last.flatMap { file =>
read(file).map(...).through(saveNow).compile.drain
}