-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Restrict attemptNarrow to subtypes of Throwable #3361
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3361 +/- ##
=======================================
Coverage 93.34% 93.34%
=======================================
Files 378 378
Lines 7692 7692
Branches 206 203 -3
=======================================
Hits 7180 7180
Misses 512 512
Continue to review full report at Codecov.
|
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.
As a practical matter this is an improvement because exceptions don't seem to have parameterized types very often, but as you said this doesn't fix the underlying issue. I apologize for not lying down in front of the bulldozer for #2863 because this really shouldn't have made it into cats in the first place.
@tpolecat Out of curiosity, do you feel the same way about our |
@travisbrown yes, same. I dislike them both, but I can accept that utility in the common case probably outweighs unsoundness in the general case. But it does seem like we should mention it in the doc. |
If the eventual goal is to remove it, would it make more sense to just deprecate it? |
@rossabaker I see this PR is a first step, to get That puts us in a position to communicate the risks of For what it's worth I was looking at |
This change makes it impossible to call
attemptNarrow
with a type parameter that isn'tThrowable
or one of its subtypes. This makes it slightly less easy to shoot yourself in the foot with it (see #3360), while still supporting its most common use cases.The change doesn't break binary compatibility, but definitely does break source compatibility. It only breaks dangerous code, though, so I think that's fine for 2.2.0.
Personally I'd prefer to scrap it entirely (by making it package-private), since even in this restricted form it breaks parametricity in a way that feels un-Cats-like. I've chosen this route because of the precedent of
catchOnly
, which does a similar thing with runtime reflection but makes it relatively safe by restricting toThrowable
.