Skip to content
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

Client: avoid throwing outside of effect system #2502

Merged
merged 2 commits into from Apr 16, 2019
Merged

Client: avoid throwing outside of effect system #2502

merged 2 commits into from Apr 16, 2019

Conversation

@yoohaemin
Copy link
Contributor

@yoohaemin yoohaemin commented Apr 11, 2019

A json decoding failure was causing fiber death when used with ZIO.

@rossabaker
Copy link
Member

@rossabaker rossabaker commented Apr 11, 2019

There are a couple more of these in that file. Throwing in a bracket is not guaranteed by law to raise the error into F, so I agree we should change these. Would you be interested in getting the rest? It should just be a search and replace.

@yoohaemin
Copy link
Contributor Author

@yoohaemin yoohaemin commented Apr 11, 2019

Sure, will do

@rossabaker
Copy link
Member

@rossabaker rossabaker commented Apr 11, 2019

Note that there are a bunch in core, but those are Eithers, in methods named unsafe. Anywhere we're doing this outside a test or a convenience method marked as unsafe is bad.

@yoohaemin
Copy link
Contributor Author

@yoohaemin yoohaemin commented Apr 14, 2019

I wonder what the difference is between using .rethrowT and .value.flatMap(_.fold(F.raiseError(_), F.pure(_))) from the other PR. Would there be a meaningful difference?

@rossabaker
Copy link
Member

@rossabaker rossabaker commented Apr 14, 2019

It's usually not meaningful, but yours has a slight chance at being better:

  • .rethrowT is MonadError[F, Throwable].rethrow(value).
  • MonadError[F, Throwable].rethrow defaults to flatMap(fa)(_.fold(raiseError, pure)), but maybe some F out there somewhere optimized it.

typelevel/cats#2237 will give us a better way still.

@rossabaker rossabaker merged commit 417a168 into http4s:master Apr 16, 2019
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants