From 2589483fcefa472e7ca0457bf70f0c0195fa1086 Mon Sep 17 00:00:00 2001 From: "John A. De Goes" Date: Fri, 21 Jul 2023 13:14:36 +0100 Subject: [PATCH] workaround scalac bugs --- zio-http/src/main/scala/zio/http/Response.scala | 1 - zio-http/src/test/scala/zio/http/HttpAppSpec.scala | 6 ++++-- zio-http/src/test/scala/zio/http/ResponseSpec.scala | 8 ++++---- zio-http/src/test/scala/zio/http/RouteSpec.scala | 6 ++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/zio-http/src/main/scala/zio/http/Response.scala b/zio-http/src/main/scala/zio/http/Response.scala index 53bf2cf040..4bd5f7efb5 100644 --- a/zio-http/src/main/scala/zio/http/Response.scala +++ b/zio-http/src/main/scala/zio/http/Response.scala @@ -426,7 +426,6 @@ object Response { case _: IllegalAccessError => error(Status.Forbidden, throwable.getMessage) case _: NotDirectoryException => error(Status.BadRequest, throwable.getMessage) case _: IllegalArgumentException => error(Status.BadRequest, throwable.getMessage) - case _: IllegalFormatException => error(Status.BadRequest, throwable.getMessage) case _: java.io.FileNotFoundException => error(Status.NotFound, throwable.getMessage) case _: java.net.ConnectException => error(Status.ServiceUnavailable, throwable.getMessage) case _: java.net.SocketTimeoutException => error(Status.GatewayTimeout, throwable.getMessage) diff --git a/zio-http/src/test/scala/zio/http/HttpAppSpec.scala b/zio-http/src/test/scala/zio/http/HttpAppSpec.scala index ea1cc7d77c..db77507bd5 100644 --- a/zio-http/src/test/scala/zio/http/HttpAppSpec.scala +++ b/zio-http/src/test/scala/zio/http/HttpAppSpec.scala @@ -21,20 +21,22 @@ import zio.test.Assertion._ import zio.test._ object HttpAppSpec extends ZIOSpecDefault { + def extractStatus(response: Response): Status = response.status + def spec = suite("HttpAppSpec")( test("empty not found") { val app = HttpApp.empty for { result <- app.run() - } yield assertTrue(result.status == Status.NotFound) + } yield assertTrue(extractStatus(result) == Status.NotFound) }, test("compose empty not found") { val app = HttpApp.empty ++ HttpApp.empty for { result <- app.run() - } yield assertTrue(result.status == Status.NotFound) + } yield assertTrue(extractStatus(result) == Status.NotFound) }, test("run identity") { val body = Body.fromString("foo") diff --git a/zio-http/src/test/scala/zio/http/ResponseSpec.scala b/zio-http/src/test/scala/zio/http/ResponseSpec.scala index a6fa49d230..59e4d76d0a 100644 --- a/zio-http/src/test/scala/zio/http/ResponseSpec.scala +++ b/zio-http/src/test/scala/zio/http/ResponseSpec.scala @@ -34,20 +34,20 @@ object ResponseSpec extends ZIOSpecDefault { test("from IllegalArgumentException") { val cause = Cause.fail(new IllegalArgumentException) - assertTrue(Response.fromCause(cause).status == Status.BadRequest) + assertTrue(extractStatus(Response.fromCause(cause)) == Status.BadRequest) }, test("from String") { val cause = Cause.fail("error") - assertTrue(Response.fromCause(cause).status == Status.InternalServerError) + assertTrue(extractStatus(Response.fromCause(cause)) == Status.InternalServerError) }, ), suite("fromThrowable")( test("from Throwable") { - assertTrue(Response.fromThrowable(new Throwable).status == Status.InternalServerError) + assertTrue(extractStatus(Response.fromThrowable(new Throwable)) == Status.InternalServerError) }, test("from IllegalArgumentException") { - assertTrue(Response.fromThrowable(new IllegalArgumentException).status == Status.BadRequest) + assertTrue(extractStatus(Response.fromThrowable(new IllegalArgumentException)) == Status.BadRequest) }, ), suite("redirect")( diff --git a/zio-http/src/test/scala/zio/http/RouteSpec.scala b/zio-http/src/test/scala/zio/http/RouteSpec.scala index 1fbf97d750..a5f1693450 100644 --- a/zio-http/src/test/scala/zio/http/RouteSpec.scala +++ b/zio-http/src/test/scala/zio/http/RouteSpec.scala @@ -22,6 +22,8 @@ import zio._ import zio.test._ object RouteSpec extends ZIOSpecDefault { + def extractStatus(response: Response): Status = response.status + def spec = suite("RouteSpec")( suite("Route#sandbox")( test("infallible route does not change under sandbox") { @@ -32,7 +34,7 @@ object RouteSpec extends ZIOSpecDefault { for { result <- ignored.toHandler.run().merge - } yield assertTrue(result.status == Status.Ok) + } yield assertTrue(extractStatus(result) == Status.Ok) }, test("route dying with throwable ends in internal server error") { val route = @@ -43,7 +45,7 @@ object RouteSpec extends ZIOSpecDefault { for { result <- ignored.toHandler.merge.run() - } yield assertTrue(result.status == Status.InternalServerError) + } yield assertTrue(extractStatus(result) == Status.InternalServerError) }, ), suite("auto-sandboxing for middleware")(