Skip to content
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

Better definition of async exceptions #53

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ before_cache:

matrix:
include:
- env: CABALVER=1.16 GHCVER=7.6.3
compiler: ": #GHC 7.6.3"
addons: {apt: {packages: [cabal-install-1.16,ghc-7.6.3], sources: [hvr-ghc]}}
- env: CABALVER=1.18 GHCVER=7.8.4
compiler: ": #GHC 7.8.4"
addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}}
Expand Down
12 changes: 8 additions & 4 deletions Control/Error/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ import Data.Semigroup
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import System.IO (stderr)
import UnexceptionalIO (Unexceptional)

import qualified Control.Exception as Exception
import qualified Data.Text.IO
import qualified UnexceptionalIO as UIO

-- | Fold an 'ExceptT' by providing one continuation for each constructor
exceptT :: Monad m => (a -> m c) -> (b -> m c) -> ExceptT a m b -> m c
Expand Down Expand Up @@ -276,5 +274,11 @@ handleExceptT handler = bimapExceptT handler id . ExceptT . try
{-| Catch all exceptions, except for asynchronous exceptions found in @base@
and convert them to the 'ExceptT' monad
-}
syncIO :: Unexceptional m => IO a -> ExceptT SomeException m a
syncIO = ExceptT . UIO.liftUIO . UIO.fromIO
syncIO :: MonadIO m => IO a -> ExceptT SomeException m a
syncIO = ExceptT . liftIO . trySync

trySync :: IO a -> IO (Either SomeException a)
trySync io = (fmap Right io) `Exception.catch` \e ->
case Exception.fromException e of
Just (Exception.SomeAsyncException _) -> Exception.throwIO e
Nothing -> return (Left e)
7 changes: 3 additions & 4 deletions errors.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Name: errors
Version: 2.2.5
Cabal-Version: >=1.8.0.2
Build-Type: Simple
Tested-With: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2, GHC == 8.0.1
Tested-With: GHC == 7.8.4, GHC == 7.10.2, GHC == 8.0.1
License: BSD3
License-File: LICENSE
Copyright: 2012, 2013 Gabriel Gonzalez
Expand All @@ -24,12 +24,11 @@ Source-Repository head

Library
Build-Depends:
base >= 4 && < 5 ,
base >= 4.7 && < 5 ,
exceptions >= 0.6 && < 0.11,
text < 1.3 ,
transformers >= 0.2 && < 0.6 ,
transformers-compat >= 0.4 && < 0.7 ,
unexceptionalio >= 0.3 && < 0.4
transformers-compat >= 0.4 && < 0.7
if impl(ghc <= 7.6.3)
Build-Depends:
safe >= 0.3.3 && < 0.3.10
Expand Down