-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClassCassException when using HandlerAspect and Path parameters. #3141
Comments
/bounty $150 for fix and test case. |
💎 $150 bounty • ZIOSteps to solve:
Thank you for contributing to zio/zio-http! Add a bounty • Share on socials
|
/attempt #3141
|
💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward. |
@varshith257: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏 |
The bounty is up for grabs! Everyone is welcome to |
Any update on this? |
I have a proposal. But it is breaking. I want to take a look agin together with @jdegoes |
I took a quick look at the PR. Am I right in thinking that we are trying to convert a runtime ClassCastException into a compiler error? Of course it would be better to have a compile time error, but I think there is a bigger question -- Why can't HandlerAspects be usable for Handlers with inputs such as As it is, it seems impossible for me to combine my authentication HandlerAspect with a Maybe it would make more sense to stick the path codecs into the |
FWIW here is my failing case. it gives the same ClassCastException: object ChallengeSpec extends ZIOSpecDefault:
def handleMessage(message: String, request: Request): ZIO[Int, Response, Response] =
ZIO.service[Int].map(i => Response.text(s"$message $i"))
val authenticationAspect: HandlerAspect[Any, Int] =
HandlerAspect.interceptIncomingHandler(Handler.fromFunction[Request] { request =>
(request, 7)
})
val routes = Routes(
Method.DELETE / string("message") -> handler(handleMessage) @@ authenticationAspect
)
def spec = test("handler should route") {
for
response <- routes.runZIO(Request.delete(URL(root) / "twenty"))
body <- response.body.asString
yield
assert(response.status)(equalTo(Status.Ok)) &&
assert(body)(equalTo("twenty 7"))
} It seems I have two paths forward: Either rewrite |
Describe the bug
We are getting ClassCastExceptions when using a route with Path paramters, and a middleware that adds context.
class zio.http.Request cannot be cast to class scala.Tuple2 (zio.http.Request and scala.Tuple2 are in unnamed module of loader 'app')
Tuple2 is increasing if we add more path params
To Reproduce
Run this snipped
run:
curl -v 127.0.0.1:8080/base/1
Expected behaviour
Log Hello and return 200 Ok
Additional context
Same error in scala 2 and 3.
Using Intellij breakpoints on all exception, it stops at Handler.scala - line 57
The text was updated successfully, but these errors were encountered: