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

fromTryCatch shouldn't infer Null #591

Closed
ceedubs opened this issue Oct 30, 2015 · 1 comment
Closed

fromTryCatch shouldn't infer Null #591

ceedubs opened this issue Oct 30, 2015 · 1 comment

Comments

@ceedubs
Copy link
Contributor

ceedubs commented Oct 30, 2015

If you don't explicitly provide a type parameter to fromTryCatch (on either Xor or Validated), the type parameter defaults to Null and it doesn't actually catch exceptions.

scala> Xor.fromTryCatch(throw new RuntimeException("blargh"))
java.lang.RuntimeException: blargh
  at $anonfun$1.apply(<console>:17)
  at $anonfun$1.apply(<console>:17)
  at cats.data.XorFunctions$FromTryCatchAux.apply(Xor.scala:229)
  ... 43 elided

scala> Xor.fromTryCatch
res1: cats.data.Xor.FromTryCatchAux[Null] = cats.data.XorFunctions$FromTryCatchAux@1039a2fc

scala> Xor.fromTryCatch[Throwable](throw new RuntimeException("blargh"))
res2: cats.data.Xor[Throwable,Nothing] = Left(java.lang.RuntimeException: blargh)

I think we should do two things here:

  1. Add a helper to catch NonFatal exceptions, as that is probably generally what people want. This could be called fromTryCatchNonFatal or just catchNonFatal if the former is too verbose.
  2. Make fromTryCatch take implicit evidence that the type parameter is not an unhelpful type such as Nothing (do we need to cover Null too?). Scalaz does this: https://github.com/scalaz/scalaz/blob/series/7.2.x/core/src/main/scala/scalaz/NotNothing.scala
@ceedubs
Copy link
Contributor Author

ceedubs commented Nov 10, 2015

Fixed in #592

@ceedubs ceedubs closed this as completed Nov 10, 2015
@ceedubs ceedubs removed the ready label Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant