http4s / http4s

A minimal, idiomatic Scala interface for HTTP

Home Page:https://http4s.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docs: Error handling example does not compile

raquo opened this issue · comments

Hello, the error handling example in the docs does not compile with 0.23.23 & Scala 3: https://http4s.org/v0.23/docs/error-handling.html

case req @ GET -> "error" says:

Found: ("error" : String)
Required: org.http4s.Uri.Path
pattern type is incompatible with expected type
case req @ GET -> "error" =>

I'm not sure if I'm missing some import, or what it's supposed to be, but it works with GET -> Root / "error"

Also this expression in withErrorLogging seems to be the wrong type:

IO.println(msg) >>
  IO.println(t)

Found: cats.effect.IO[Unit]
Required: cats.data.OptionT[cats.effect.IO, Unit]
IO.println(msg) >>

Again, not sure if missing an import, but if so, it should be in the docs, since that section is for beginners.
I wrapped it in OptionT.liftF and it seems to work:

OptionT.liftF[IO, Unit]((IO.println(msg) >> IO.println(t) >> IO.delay(t.printStackTrace())).map(_ => Some(()))),

The source for those docs are here:
https://github.com/http4s/http4s/blob/285af55cc5810e125a962dc88f3d52d50074e99f/docs/docs/error-handling.md

Currently the snippets are not checked by mdoc, like the rest of the documentation, so it's not entirely surprising that it is broken.