-
Notifications
You must be signed in to change notification settings - Fork 517
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
Make IO#onError
consistent with ApplicativeError
#4121
Merged
armanbilge
merged 8 commits into
typelevel:series/3.x
from
lenguyenthanh:make-io-onError-consistent-with-applicative-error
Aug 28, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
932fa7d
Make IO.onError consistent with Applicative.onError
lenguyenthanh b4cd5e5
Replace usage of the old onError with the new one
lenguyenthanh 7825274
Make scala 2.12 happy
lenguyenthanh f4f505c
Reuse logic between IO.onError
lenguyenthanh 40a7dde
Add reportError helper and use it for onError
lenguyenthanh 4764d05
Use reportError when applicable
lenguyenthanh 868451b
Fix onError callback error handling semantic
lenguyenthanh c6026b3
Override onError for IOAsync
lenguyenthanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To match the other implementation we need this
voidError
. But this raises an interesting question about the semantics: if theonError
callback raises an error, which error should be propagated, that error or the original one? Also thevoidError
completely discards the error without reporting it, which seems really weird 😕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 what we should do is extract this into a helper method.
cats-effect/core/shared/src/main/scala/cats/effect/IO.scala
Line 493 in 7168625
Then instead of
voidError
we should redirect errors within theonError
callback to that? And then re-raise the original error.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 @armanbilge, I'm completely missed that
voidError
. I addedreportError
helper method as your suggestion. I think this is a great improvement. The name is subjecting for bike-shedding. We can also use thisreportError
method in the two other places. I can do that in this pr.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.
Yes, I almost missed it as well. We should add a test to cover this case (what happens if
onError
callback raises an error), that would have helped us. Actually we might even consider adding this as a law to Cats, so thatonError
semantics are the same across all implementations.🚀 it looks good! I think name is reasonable and it is private internal anyway.
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.
cool, I'll add a test case for in this first. And think about a law for cats later on.
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.
Hmm, actually, now I am hesitating 😅
The goal of this PR is to make
IO#onError
consistent withApplicativeError#onError
. If we usevoidError
/reportError
then the semantics are inconsistent again withApplicativeError
😕https://github.com/typelevel/cats/blob/8e8724a29881a394bc39357a7f0cd21124573f30/core/src/main/scala/cats/ApplicativeError.scala#L261-L262
Unless we change it in Cats (and this may be too drastic of a change) I think we just have to let the callback's error propagate instead.
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.
ahhhh, you're right. So, my first implemenaton was accidentally correct :p.