Commit 91c00c5
committed
rethrow
feat: support for exception context propagation
We specialize the `throwIO` call using a newly implemented `rethrowIO'`
which behaves as `rethrowIO` from base 4.21 when available or like the
previous `throw` implementation.
In short:
- Before `base-4.21`, the code is exactly as before
- After `base-4.21`, the code does not override the backtrace
annotations and instead uses `rethrowIO`.
Example of usage / changes:
The following code:
```haskell
{-# LANGUAGE DeriveAnyClass #-}
import Control.Concurrent.Async
import Control.Exception
import Control.Exception.Context
import Control.Exception.Annotation
import Data.Typeable
import Data.Traversable
import GHC.Stack
data Ann = Ann String
deriving (Show, ExceptionAnnotation)
asyncTask :: HasCallStack => IO ()
asyncTask = annotateIO (Ann "bonjour") $ do
error "yoto"
asyncTask' :: HasCallStack => IO ()
asyncTask' = annotateIO (Ann "bonjour2") $ do
error "yutu"
main = do
-- withAsync asyncTask wait
concurrently asyncTask asyncTask'
-- race asyncTask asyncTask'
```
When run without this commit leads to:
```
ASyncException.hs: Uncaught exception ghc-internal:GHC.Internal.Exception.ErrorCall:
yoto
HasCallStack backtrace:
throwIO, called at ./Control/Concurrent/Async/Internal.hs:630:24 in async-2.2.5-50rpfAJ7BEc1o5OswtTMUN:Control.Concurrent.Async.Internal
```
When run with this commit:
```
*** Exception: yoto
Ann "bonjour"
HasCallStack backtrace:
error, called at /home/guillaume//ASyncException.hs:15:3 in async-2.2.5-inplace:Main
asyncTask, called at /home/guillaume//ASyncException.hs:23:16 in async-2.2.5-inplace:Main
```1 parent 7ac0e51 commit 91c00c5
1 file changed
+19
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
185 | | - | |
| 186 | + | |
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
189 | 203 | | |
190 | 204 | | |
191 | 205 | | |
| |||
613 | 627 | | |
614 | 628 | | |
615 | 629 | | |
616 | | - | |
| 630 | + | |
617 | 631 | | |
618 | 632 | | |
619 | 633 | | |
| |||
627 | 641 | | |
628 | 642 | | |
629 | 643 | | |
630 | | - | |
| 644 | + | |
631 | 645 | | |
632 | 646 | | |
633 | 647 | | |
| |||
640 | 654 | | |
641 | 655 | | |
642 | 656 | | |
643 | | - | |
| 657 | + | |
644 | 658 | | |
645 | 659 | | |
646 | 660 | | |
| |||
699 | 713 | | |
700 | 714 | | |
701 | 715 | | |
702 | | - | |
| 716 | + | |
703 | 717 | | |
704 | 718 | | |
705 | 719 | | |
| |||
0 commit comments