-
Notifications
You must be signed in to change notification settings - Fork 72
feat: support for exception context propagation #165
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
Open
guibou
wants to merge
8
commits into
simonmar:master
Choose a base branch
from
novainsilico:no_discard_exception_context
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e1d4296
feat: support for exception context propagation
guibou 6dad253
feat: add exceptions rethrow tests
guibou fb9bfd3
feat: `withAsync` does not wrap exception in the inner block with Whi…
guibou e84ad66
feat: annotate 'waitXXX' function with the callsite for 'wait'
guibou 91a23d5
feat: add tests for location of `wait` call annotation
guibou 3f7e6de
refactor: alternate implementation for exception context
guibou 887ebea
feat: reexport the compatibility API
guibou bcf84de
chore: update the changelog with exception context propagation details
guibou 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
AFAICT,
concurrently'is an internal, not exposed combinator, so I suggest that it's changed fromto
i.e.
catch->catchNoPropagatechange. If I'm looking right, that would remove the need for very suspicious lookingrethrowIO', thebase'srethrowIOwill be enough.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.
Also,
catchAllin the body should probably becatchNoPropogate.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.
@phadej I agree with your proposal, but it mean that the complete
concurrently'block would be duplicated with a#if MIN_VERSION_base(4,21,0)pragma. And similarly, if you want to avoid therethrowIO'function, we also need to duplicate all therethrowIO'callsite to dispatch betweenrethrowIOandthrowIO. This is a lot of code duplication, unless I missunderstood your proposal.Note that I do admit that
rethrowIO'is suspicious, but it is well localised and seems safe becauseSomExceptionmay contain an exception context (Actually, it will always contain one, unless it was explicitely removed).Regarding
catchAllversuscatchNoPropagate. I would claim that in this context we do not really care.The point of
catchNoPropagateis for the handler to possibly rethrow the exception explicitely and hence not having theWhileHandlingwrapping an a new callstack. Here the handler is aputMVar done . Leftwhich does not explicitely rethrow the exception (hence theWhileHandlingwon't happen), unless another exception happen during theputMVarand I would admit that this context is, from my understanding, rare or even impossible, but actually not a "normal" use case of the async library, and does not fall into the the scope of this MR (e.g. improving exception context in "normal" use case, meaning when an exception happen in the task run by the library, no in its internals).The "problem" with
catchNoPropagateis that it returns anExceptionWithContextand if we want to store that inside themvar, we actually need to patch all the library.I think my approach is imperfect because of backward compatibility. When later we'll drop support for base <4.21, we'll be able to rewrite the complete library and turns all the
rethrowIO'to properrethrowIOand all theSomeExceptionto properExceptionWithContext SomeException, but this is not doable immediately without tones of CPP.@phadej I see a few options here:
a) Keep the implementation as it is right now
b) Introduce a lot of CPP everywhere
c) Copy paste everything in another module and do conditional build based on the base version
d) Drop support for base <4.21 and do a "major"
asyncrelease and maybe maintain the old one in a different branch with a different version number?e) (I just thought about it): use CPP only in a really localised place to implement
rethrowIO,catchNoPropagateandExceptionWithContextwhich would map either tothrowIO,catchandSomeExceptionor the version from base>= 4.21. Actually, this may be the best option. Do you want me to attempt this refactor?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.
@phadej, @Bodigrim, would you have a look at the latest commit which tries a different approach: using
tryWithContext/catchNoPropagateeverywhere and adding a simple compatibility layer.The test fails with GHC 9.10, I'm investigating, but I would like to know first if you prefer this approach.