zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
800 stars 403 forks source link

Server doesn't print unexpected error logs #2491

Open livelxw opened 1 year ago

livelxw commented 1 year ago

Describe the bug The server doesn't print error logs when exceptions were thrown.

To Reproduce Scala 3:

import zio.http.*
import zio.{Scope, ZIO, ZIOAppArgs, ZIOAppDefault, ZLayer}

object Test extends ZIOAppDefault {
  val app = Http.collectZIO[Request] { case Method.GET -> Root / "test" => throw RuntimeException("test error") }

  override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] = {
    Server
      .serve(app)
      .provide(
        ZLayer.succeed(Server.Config.default.enableRequestStreaming.port(8080)),
        Server.live
      )
  }
}

When send a request to http://localhost:8080/test, it responds empty body with 500 status code, and no error logs in server.

Expected behaviour It should print error logs in server.

jdegoes commented 10 months ago

/bounty $75

To fix and add a reproducer testcase.

algora-pbc[bot] commented 10 months ago

💎 $75 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2491 with your implementation plan
  2. Submit work: Create a pull request including /claim #2491 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bounty • Share on socials

Attempt Started (GMT+0) Solution
🟢 @cheikhsimsol Jan 6, 2024, 10:26:44 PM WIP
cheikhsimsol commented 10 months ago

/attempt #2491

Options
achinaou commented 2 months ago

I observe the same behavior with the latest version.

//> using scala 3.5.0

//> using dep dev.zio::zio-http:3.0.0

import zio.*
import zio.http.*

object Application extends ZIOAppDefault:

  val routes: Routes[Any, Nothing] =
    Routes(Method.GET / Root -> Handler.die(NotImplementedError()))

  override val run: ZIO[Any, Any, Any] =
    Server
      .serve(routes)
      .provide(Server.default)

In this example, the error won't be logged.