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
Deprecates Client#fetch #3372
Deprecates Client#fetch #3372
Conversation
I'd like to get confirmations on 1 and 2 if I can do it:
@rossabaker, WDYT? |
4e3a158
to
9940a6a
Compare
@@ -24,6 +24,7 @@ trait Client[F[_]] { | |||
* response body afterward will result in an error. | |||
* @return The result of applying f to the response to req | |||
*/ | |||
@deprecated("Use run(req).use(f)", "0.21") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually put patch versions in these, so 0.21.5.
scalafix/build.sbt
Outdated
@@ -27,29 +27,32 @@ lazy val rules = project.settings( | |||
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.scalafixVersion | |||
) | |||
|
|||
val http4sInputVersion = "0.21.4" | |||
val http4sOutputVersion = "0.21.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.18 is ancient, but it's also a shame to lose the old rules. Is there a way to version these, so people might run multiple iterations if catching up across multiple versions? Probably related to these "semantic rules," but I would need to refresh my memory how these work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the old rules don't even compile with the newer http4s version. I'd also prefer to keep the old rules but have no idea how to achieve it easily. But I'm open to any suggestions:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps @amarrella remembers how this works, as the original contributor. If not, we can learn together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a long time since I've looked at these but can we perhaps set the old version as a dependency instead of depending on the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amarrella sorry, not sure if I caught it. Could you explain your idea a bit more please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satorg apologies, I misunderstood the problem. I see the issue now with keeping http4sInputVersion = 0.18.x
:(
Perhaps the cleanest version is getting rid of the rules like you did, and point users to use a older version of the jar if they need the older rule and then updating to the new one. I know it's way less ergonomic though :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think we also could convert the scalafix directory into a multi-module project where each module has its own set of dependencies. But I'm not sure if it's a really good way to go.
2b63235
to
6cb704f
Compare
I think I almost done with scalafix rules. But there's still a question about what should we do with the old rules. BTW, once scalafix rules are implemented how can I apply them to the base http4s project's sources? cc @rossabaker, @amarrella |
212ee99
to
5d9de5c
Compare
That's a great question on how to run them on our own sources. Can you use |
6f8058e
to
f2a25a1
Compare
@rossabaker I think I finished the scalafix rules for this task. |
BTW, I realized that there are some cases which cannot be fixes properly. For example, consider the following: trait MyIntermediateService[F[_]] {
def client: Client[F[_]]
final def someFuncThatCallsClientFetch[A](req: Request[F]): F[A] = {
client.fetch(req) { res => /* do something */ }
}
} The problem with this sample is that |
ah, that's a great point. It would be nice if we could somehow inject a custom error for that somewhere |
Hmm... any ideas on that? As an alternative we could try to add a TODO comment to point out at the problematic line. |
0133a66
to
4849b27
Compare
@rossabaker I managed to run the new rule on the project sources in this way:
|
@@ -30,6 +30,7 @@ trait Client[F[_]] { | |||
* response body afterward will result in an error. | |||
* @return The result of applying f to the response to req | |||
*/ | |||
@deprecated("Use run(req).use(f)", "0.21.5") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I question whether this message should indicate, "Don't use fetch
, but, if you must, do run(req).use(f)
per the helpful discussion in #3345 (comment) regarding what's wrong with fetch
.
Thoughts, @rossabaker and @satorg?
I admit that I don't know if "why is it deprecated" should be placed inside of the @deprecated
's message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't get, what is your concern about the message? Do you think it should be more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the message is in line with what we usually do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my question, satorg and Ross.
bd4d12f
to
ff4ad72
Compare
Oh, are we targeting 0.21.5 with this? I thought we were, and the deprecation warnings say so, but I just noticed that it's on master. |
Yes, it is.. It was on 'master' from the beginning.. As I've realized now, I should rebase it onto '0.21.5'... I'll do it later today, sorry for misunderstanding. |
Okay, I've rebased this one onto 0.21 so it's part of that release. Thanks, @satorg, for the excellent work on both the deprecation and improving our scalafix situation. This was a long ticket, but well worth it. |
I just learned about the new Scalafix migrations via the release notes of 0.21.5. I think it would be nice to add the new migration to Scala Steward although it already created a lot of PRs for http4s 0.21.5 without it. For future releases it would be nice to add new migrations to Scala Steward before a new version is released to ensure that Scala Steward can run them on all open source projects it is working on. |
Oh, I knew that scalafix integration had been discussed, but I didn't realize it was a reality. Very cool! |
The rule for http4s 0.20.0 was even one of the first migrations added to Scala Steward and was used in 30+ PRs although it was also added after the 0.20.0 release. |
Would the right thing to do be to add the new rule now, then? |
Oh, I should have looked at your linked PR. |
I've added the new migration in scala-steward-org/scala-steward#1510. It will be applied to updates going from x < 0.21.5 to y >= 0.21.5. For future migrations, you can ping me when they are discussed/merged and I can help with adding them to Scala Steward. |
Fixes #3345
Tasks to complete:
@deprecate
annotation to theseClient
methods:fetch
in the project code (including tests) by replacing it withrun
followed byuse
1.1: There were some test cases which lost their sense after all the replacements because they turned into identical cases for the
run
method. Such cases were deleted.2: (UPD: RESOLVED) Initially the scalafix subproject had the following dependency versions on http4s:
To elaborate scalafix rules for this PR, the versions above were updated to "0.21.4" for both input and output. The old rules were removed.
If we wish to preserve the old rules, I see two ways to achieve it:
I'd assume that p.2 is more preferable and easy to manage, but I'm open to discussion.
3: Not all possible cases are handled in the rules mostly due to scalafix limitations. It includes cases where typeclasses like
Bracket
orFlatMap
are not available forF[_]
in a call site offetch
, but they're necessary for a new statement which replaces the old one. Unfortunately, scalafix doesn't allow to check whether some typeclass available for a particular type in a document tree or not. See this comment for an example.