Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragge-dev committed Apr 6, 2024
1 parent 6ff2fb2 commit 1fde620
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion result/src/main/scala/io/github/ragazoor/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sealed trait IO[+E <: Throwable, +A] extends Awaitable[A] {
def mapError[E2 <: Throwable](f: E => E2)(implicit ec: ExecutionContext): IO[E2, A] = {
var isFutureFatal = isFatal
val transformedFuture = self.toFuture.transform {
case Failure(e) if NonFatal(e) || !isFatal => Failure(f(e.asInstanceOf[E]))
case Failure(e) if NonFatal(e) && !isFatal => Failure(f(e.asInstanceOf[E]))
case Failure(e) if !NonFatal(e) || isFatal =>
isFutureFatal = true
Failure(e)
Expand Down
19 changes: 10 additions & 9 deletions result/src/test/scala/io/github/ragazoor/IOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,21 @@ class IOSpec extends FunSuite {
.map(result => assert(result == 2))
}


test("IO mapError cannot catch fatal errors") {
val result = for {
_ <- IO.fatal(new RuntimeException("Test message"))
} yield assert(false)

result
.mapError(MyError.apply)
.catchSome { case _: MyError =>
IO.successful(assert(false))
}
.toFuture
.recover {
case _: RuntimeException => assert(true)
}
.mapError(MyError.apply)
.catchSome { case _: MyError =>
IO.successful(assert(false))
}
.toFuture
.recover {
case _: RuntimeException => assert(true)
case e => assert(e.getMessage == "Test message")
}

}
}

0 comments on commit 1fde620

Please sign in to comment.