safe-exceptions 0.1.6.0 → 0.1.7.0
raw patch · 3 files changed
+31/−18 lines, 3 filesdep ~basedep ~exceptions
Dependency ranges changed: base, exceptions
Files
- ChangeLog.md +4/−0
- safe-exceptions.cabal +1/−1
- src/Control/Exception/Safe.hs +26/−17
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.1.7.0++* Add `bracketWithError`+ ## 0.1.6.0 * Reuse the `Handler` definition from `Control.Monad.Catch`
safe-exceptions.cabal view
@@ -1,5 +1,5 @@ name: safe-exceptions-version: 0.1.6.0+version: 0.1.7.0 synopsis: Safe, consistent, and easy exception handling description: Please see README.md homepage: https://github.com/fpco/safe-exceptions#readme
src/Control/Exception/Safe.hs view
@@ -56,6 +56,7 @@ , withException , bracketOnError , bracketOnError_+ , bracketWithError -- * Coercion to sync and async , SyncExceptionWrapper (..)@@ -375,25 +376,10 @@ -- | Async safe version of 'E.bracket' ----- @since 0.1.0.0+-- @since 0.1.7.0 bracket :: forall m a b c. C.MonadMask m => m a -> (a -> m b) -> (a -> m c) -> m c-bracket before after thing = C.mask $ \restore -> do- x <- before- res1 <- C.try $ restore (thing x)- case res1 of- Left (e1 :: SomeException) -> do- -- explicitly ignore exceptions from after. We know that- -- no async exceptions were thrown there, so therefore- -- the stronger exception must come from thing- --- -- https://github.com/fpco/safe-exceptions/issues/2- _ :: Either SomeException b <-- C.try $ C.uninterruptibleMask_ $ after x- C.throwM e1- Right y -> do- _ <- C.uninterruptibleMask_ $ after x- return y+bracket before after = bracketWithError before (const after) -- | Async safe version of 'E.bracket_' --@@ -438,6 +424,29 @@ -- @since 0.1.0.0 bracketOnError_ :: C.MonadMask m => m a -> m b -> m c -> m c bracketOnError_ before after thing = bracketOnError before (const after) (const thing)++-- | Async safe version of 'E.bracket' with access to the exception in the+-- cleanup action.+--+-- @since 0.1.0.0+bracketWithError :: forall m a b c. C.MonadMask m+ => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c+bracketWithError before after thing = C.mask $ \restore -> do+ x <- before+ res1 <- C.try $ restore (thing x)+ case res1 of+ Left (e1 :: SomeException) -> do+ -- explicitly ignore exceptions from after. We know that+ -- no async exceptions were thrown there, so therefore+ -- the stronger exception must come from thing+ --+ -- https://github.com/fpco/safe-exceptions/issues/2+ _ :: Either SomeException b <-+ C.try $ C.uninterruptibleMask_ $ after (Just e1) x+ C.throwM e1+ Right y -> do+ _ <- C.uninterruptibleMask_ $ after Nothing x+ return y -- | Wrap up an asynchronous exception to be treated as a synchronous -- exception