packages feed

exitcode 0.1.0.8 → 0.1.0.9

raw patch · 4 files changed

+50/−17 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Control.Exitcode: liftTryExitcode :: Exception e' => IO a -> ExitcodeT (ExceptT e' IO) e a
+ Control.Process.Process: getProcessExitCodeBool :: Exception e' => ProcessHandle -> ExitcodeT (ExceptT e' IO) Bool Bool
- Control.Exitcode: tryExitcode :: Exception e' => ExitcodeT IO e a -> ExitcodeT (ExceptT e' IO) e (Either e' a)
+ Control.Exitcode: tryExitcode :: Exception e' => ExitcodeT IO e a -> ExitcodeT (ExceptT e' IO) e a
- Control.Process.Process: getProcessExitCode :: ProcessHandle -> ExitcodeT0 (MaybeT IO)
+ Control.Process.Process: getProcessExitCode :: Exception e' => ProcessHandle -> ExitcodeT (ExceptT e' IO) (Maybe ()) (Maybe ())
- Control.Process.Process: readCreateProcessWithExitCode :: CreateProcess -> String -> ExitcodeT1 IO (String, String)
+ Control.Process.Process: readCreateProcessWithExitCode :: Exception e' => CreateProcess -> String -> ExitcodeT (ExceptT e' IO) (String, String) (String, String)
- Control.Process.Process: readProcessWithExitCode :: FilePath -> [String] -> String -> ExitcodeT1 IO (String, String)
+ Control.Process.Process: readProcessWithExitCode :: Exception e' => FilePath -> [String] -> String -> ExitcodeT (ExceptT e' IO) (String, String) (String, String)
- Control.Process.Process: waitForProcess :: ProcessHandle -> ExitcodeT0 IO
+ Control.Process.Process: waitForProcess :: Exception e' => ProcessHandle -> ExitcodeT (ExceptT e' IO) () ()

Files

changelog.md view
@@ -1,3 +1,9 @@+0.1.0.9++* add exceptions to `Process` functions+* add `liftTryExitcode`+* add `getProcessExitCodeBool`+ 0.1.0.8  * add `tryExitcode`
exitcode.cabal view
@@ -1,7 +1,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                   exitcode-version:                0.1.0.8+version:                0.1.0.9 synopsis:               Monad transformer for exit codes description:   <<https://system-f.gitlab.io/logo/systemf-450x450.jpg>>
src/Control/Exitcode.hs view
@@ -39,6 +39,7 @@ , runExitcode1 -- * Exceptions , tryExitcode+, liftTryExitcode -- * Optics , exitCode , _ExitcodeInt@@ -109,7 +110,7 @@ import Data.Tuple ( uncurry ) import GHC.Show ( Show(showsPrec) ) import System.Exit ( ExitCode(..) )-import System.IO+import System.IO ( IO )  -- $setup -- >>> import Prelude@@ -739,12 +740,21 @@ runExitcode1 =   runIdentity . runExitcodeT1 +-- | Try the IO action producing the exitcode, possibly throwing an exception. tryExitcode ::   Exception e' =>   ExitcodeT IO e a-  -> ExitcodeT (ExceptT e' IO) e (Either e' a)+  -> ExitcodeT (ExceptT e' IO) e a tryExitcode (ExitcodeT x) =-  ExitcodeT (ExceptT (fmap (fmap (fmap Right)) (try x)))+  ExitcodeT (ExceptT (try x))++-- | Try the IO action producing the exitcode, possibly throwing an exception.+liftTryExitcode ::+  Exception e' =>+  IO a+  -> ExitcodeT (ExceptT e' IO) e a+liftTryExitcode x =+  ExitcodeT (ExceptT (fmap (fmap Right) (try x)))  -- | A lens to the value associated with an exitcode. --
src/Control/Process/Process.hs view
@@ -7,19 +7,26 @@ , readProcessWithExitCode , waitForProcess , getProcessExitCode+, getProcessExitCodeBool ) where  import Control.Applicative ( Applicative(pure) ) import Control.Category ( Category((.)) )+import Control.Exception ( Exception ) import Control.Exitcode-    ( ExitcodeT0,+    ( ExitcodeT,       fromExitCode',       liftExitcode,-      ExitcodeT1,+      hoistExitcode,+      tryExitcode,       _Exitcode1,-      hoistExitcode )+      liftTryExitcode ) import Control.Lens ( Identity(runIdentity), set ) import Control.Monad ( Monad((>>=)) )+import Control.Monad.Except ( ExceptT(..) )+import Data.Bifunctor ( Bifunctor(bimap) )+import Data.Bool ( Bool )+import Data.Maybe ( Maybe(..), isJust, maybe ) import Data.String ( String ) import System.FilePath( FilePath ) import System.IO ( IO )@@ -49,35 +56,45 @@   , createPipeFd   ) import qualified System.Process as P(readCreateProcessWithExitCode, readProcessWithExitCode, waitForProcess, getProcessExitCode)-import Control.Monad.Trans.Maybe ( MaybeT(MaybeT) )  readCreateProcessWithExitCode ::+  Exception e' =>   CreateProcess   -> String-  -> ExitcodeT1 IO (String, String)+  -> ExitcodeT (ExceptT e' IO) (String, String) (String, String) readCreateProcessWithExitCode p a =-  liftExitcode (P.readCreateProcessWithExitCode p a) >>= \(x, y, z) ->+  tryExitcode (liftExitcode (P.readCreateProcessWithExitCode p a)) >>= \(x, y, z) ->     hoistExitcode (pure . runIdentity) (set _Exitcode1 (y, z) (fromExitCode' x))  readProcessWithExitCode ::+  Exception e' =>   FilePath   -> [String]   -> String-  -> ExitcodeT1 IO (String, String)+  -> ExitcodeT (ExceptT e' IO) (String, String) (String, String) readProcessWithExitCode p a i =-  liftExitcode (P.readProcessWithExitCode p a i) >>= \(x, y, z) ->+  tryExitcode (liftExitcode (P.readProcessWithExitCode p a i)) >>= \(x, y, z) ->     hoistExitcode (pure . runIdentity) (set _Exitcode1 (y, z) (fromExitCode' x))  waitForProcess ::+  Exception e' =>   ProcessHandle-  -> ExitcodeT0 IO+  -> ExitcodeT (ExceptT e' IO) () () waitForProcess h =-  liftExitcode (P.waitForProcess h) >>= \x ->+  tryExitcode (liftExitcode (P.waitForProcess h)) >>= \x ->     hoistExitcode (pure . runIdentity) (fromExitCode' x)  getProcessExitCode ::+  Exception e' =>   ProcessHandle-  -> ExitcodeT0 (MaybeT IO)+  -> ExitcodeT (ExceptT e' IO) (Maybe ()) (Maybe ()) getProcessExitCode h =-  liftExitcode (MaybeT (P.getProcessExitCode h)) >>=-    hoistExitcode (pure . runIdentity) . fromExitCode'+  liftTryExitcode (P.getProcessExitCode h) >>=+    maybe (pure Nothing) (hoistExitcode (pure . runIdentity) . set _Exitcode1 (Just ()) . fromExitCode')++getProcessExitCodeBool ::+  Exception e' =>+  ProcessHandle+  -> ExitcodeT (ExceptT e' IO) Bool Bool+getProcessExitCodeBool =+  bimap isJust isJust . getProcessExitCode