Closed mschuwalow closed 1 month ago
/bounty $125 for fix and test case (may be duplicate).
/attempt #3134
with your implementation plan/claim #3134
in the PR body to claim the bountyThank you for contributing to zio/zio-http!
Add a bounty • Share on socials
Attempt | Started (GMT+0) | Solution |
---|---|---|
🟢 @mschuwalow | Sep 18, 2024, 2:47:21 PM | #3146 |
/attempt #3134
Algora profile | Completed bounties | Tech | Active attempts | Options |
---|---|---|---|---|
@mschuwalow | 1 ZIO bounty | Scala, TypeScript, Nix & more |
Cancel attempt |
💡 @mschuwalow submitted a pull request that claims the bounty. You can visit your bounty board to reward.
🎉🎈 @mschuwalow has been awarded $125! 🎈🎊
Describe the bug
Affected versions: 3.0.0-RC5+ including 3.0.0
This pr introduced changes to the error handling behaviour, allowing error handling functions to be used together with routes that don't fail / use the failure channel for responses.
Problem is that the type signature lies for handled handlers. A Handled route will not fail with a
Cause[Nothing]
, but rather with aCause[Response]
. This can cause ClassCastExceptions at runtime.For example trying to use
.handleErrorCauseZIO(c => ZIO.logInfo(Try(c.squash).toString()).as(Response.ok))
with a handled route will log aclass zio.http.Response cannot be cast to class scala.runtime.Nothing$
.Root cause are this line which casts the cause to a
Cause[Nothing]
.And this constructor of a Route using a RoutePattern and a handled handler. This function has an unused type parameter [Err] with ends up being
Nothing
unless explicitly specified.To Reproduce Steps to reproduce the behaviour:
import zio. import zio.http. import scala.util.Try
object Main extends ZIOAppDefault {
val routes = Routes( Method.GET / "foo" -> handler { _: Request => ZIO.fail(Response.ok) } ).handleErrorCauseZIO(c => ZIO.logInfo(Try(c.squash).toString()).as(Response.ok))
def run: ZIO[Environment with ZIOAppArgs with Scope,Any,Any] = Server.serve(routes).provideLayer(Server.default)
}