Weird EntityResponseGenerator behaviour since 0.20.0-M7
See original GitHub issuepackage repro
import cats.implicits._
import cats.effect._
import org.http4s.implicits._
import org.http4s.HttpRoutes
import org.http4s.server.blaze.BlazeServerBuilder
object App extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
server[IO].compile.drain.as(ExitCode.Success)
def server[F[_]: ConcurrentEffect: Timer] =
BlazeServerBuilder[F]
.bindHttp(8080, "0.0.0.0")
.withHttpApp(routes[F].orNotFound)
.serve
def routes[F[_]: Sync]: HttpRoutes[F] = {
val dsl = org.http4s.dsl.Http4sDsl[F]
import dsl._
HttpRoutes.of {
// this results in empty response, used to result in 500
case _ => Ok(prg)
}
// this works as expected, returns 500
// HttpRoutes.of {
// case _ => for {
// x <- prg
// resp <- Ok(x)
// } yield resp
// }
}
def prg[F[_]: Sync]: F[String] = Sync[F].raiseError(new RuntimeException("oh no"))
}
I think the cause is that overload of EntityResponseGenerator.apply
used to just mean flatMap
(up to 0.20.0-M6
), but now it’s deferring evaluating the F[A]
-program in a Stream.eval
of the body.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Search Results - CVE
The mission of the CVE® Program is to identify, define, and catalog publicly disclosed cybersecurity vulnerabilities.
Read more >An Assessment of Industrial Energy Options Based on Coal ...
the emphasis of the study was on the Gulf Coast area, since industries in this region arc large energy consumers and the primary...
Read more >0001193125-19-206598.txt - SEC.gov
The bases for calculating the returns were adjusted for the proposed amount of dividends after closure of the balance sheet still pending approval...
Read more >Computer Systems
This book (known as CS:APP) is for computer scientists, computer engineers, and others who want to be able to write better programs by...
Read more >license renewal environmental report additional information
For wastes not preprinted below: If you are a Very Small Quantity Generator, add the wastes to the list after the last preprinted....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
basically here https://github.com/http4s/http4s/blob/b3ea4b22fee858310ab88e9d5186457f3ec4482a/dsl/src/main/scala/org/http4s/dsl/impl/ResponseGenerator.scala#L50
you have this
F.pure(eval(body).flatMap(_.toEntity.body))
seems weird compared tobody.map(_.toEntity.body)
is there a reason for that that I don’t know?(there is also a broader discussion about having such overloads, not a massive fan)EDIT: Ah, it’s related to the introduction of the new type parameter here ofc 00cd51e ,that flatMap won’t compile. Interesting tradeoff since the reported behaviour is certainly a bit weird.
Alright, I’ll leave it to you to decide if it works just as well there.