Skip to content

Conversation

danicheg
Copy link
Member

@danicheg danicheg commented May 13, 2022

This fixes #3707.
Credit to @ChristopherDavenport and @rossabaker for their work/discussion in #3708.

@armanbilge
Copy link
Member

armanbilge commented May 13, 2022

Unfortunately, the same fix couldn't be applied for ember-client, because it has a weaker MonadCancelThrow constraint.

Can we pattern match on the constraint, to see if it is in fact Concurrent and then do the right thing in that case? This is an idea that started in Cats Effect, e.g. see typelevel/cats-effect#2771, typelevel/cats-effect#2772

Comment on lines +100 to +103
override def defaultOnError(req: Request[F])(resp: Response[F])(implicit
G: Applicative[F]
): F[Throwable] =
resp.body.compile.drain.as(UnexpectedStatus(resp.status, req.method, req.uri))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: in main this should be like

  override def defaultOnError(req: Request[F])(resp: Response[F])(implicit
      G: Applicative[F]
  ): F[Throwable] =
    resp.entity match {
      case Entity.Empty | Entity.Strict(_) =>
        F.pure(UnexpectedStatus(resp.status, req.method, req.uri))
      case Entity.Default(body, _) =>
        body.compile.drain.as(UnexpectedStatus(resp.status, req.method, req.uri))
    }

@danicheg
Copy link
Member Author

@armanbilge oh, indeed, thanks. Though I don't that much like this approach, however it works and uses many times in Typelevel libraries.

@danicheg
Copy link
Member Author

Pushing this pattern forward, we could apply it even in DefaultClient and have one version for every client. Though this pattern is kinda tricky. So maybe it'd be better to use it in particular implementations, not interfaces. I dunno, left it as-is for comments.

Comment on lines +236 to 239
def defaultOnError(req: Request[F])(resp: Response[F])(implicit
F: Applicative[F]
): F[Throwable] =
F.pure(UnexpectedStatus(resp.status, req.method, req.uri))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I was thinking we would fix this in DefaultClient instead of for the backends independently. I remember looking at the PR you linked maybe a week ago, but I didn't have this idea then.

resp.body.compile.drain.as(UnexpectedStatus(resp.status, req.method, req.uri))

case _ =>
F.pure(UnexpectedStatus(resp.status, req.method, req.uri))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case worth logging a warning that the behavior is buggy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, I believe this case shouldn't appear at runtime, because 99% of effect usage is CE.IO/monix.Task/etc effect that is supposed to have a Concurrent instance. But defaultOnError is used for serving requests overall, and end-users could even don't use logging, but this method actually will be used. So this case preserves the current behavior of request processing mostly, not just logging behavior.

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should improve things in most practice, and isn't worse anywhere.

@danicheg
Copy link
Member Author

@armanbilge Is your point strict for merging? Don't you mind if we go ahead with this as is?

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Ross, the only "strict" here is strictly improving :)

@danicheg danicheg merged commit 3e6f6e9 into http4s:series/0.23 May 16, 2022
@danicheg danicheg deleted the fix-#3707 branch May 16, 2022 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Logging On Failed Expect
3 participants