How to handle exceptions in conduit?
2012-11-01 04:26:36 GMT
Hi, there I'm writing a program communicating with external process, which can be sometimes fail, using conduit and process-conduit package. Consider the following example, which reads paths from the config file, and passes their contents to external process, and output the results: ```exc.hs module Main where import qualified Data.ByteString.Char8 as BS import Data.Conduit import qualified Data.Conduit.Binary as BC import qualified Data.Conduit.List as LC import Data.Conduit.Process main :: IO () main = runResourceT $ BC.sourceFile "paths.dat" $$ BC.lines =$= myConduit =$= LC.mapM_ (unsafeLiftIO . BS.putStrLn) myConduit :: MonadResource m => Conduit BS.ByteString m BS.ByteString myConduit = awaitForever $ \path -> BC.sourceFile (BS.unpack path) =$= conduitCmd "./sometimes-fail" ``` ```sometimes-fail.hs module Main where import System.Random main :: IO ()(Continue reading)