Permalink
Browse files

stop using Prelude.catch

  • Loading branch information...
1 parent 5d8eee8 commit 287505c9fb70f7dc9db98a14006ee36c364ef130 @hsenag hsenag committed Aug 28, 2012
Showing with 17 additions and 19 deletions.
  1. +4 −4 Network/HTTP/Base.hs
  2. +2 −2 Network/HTTP/Proxy.hs
  3. +2 −3 Network/StreamSocket.hs
  4. +9 −10 Network/TCP.hs
@@ -1,4 +1,4 @@
-{-# OPTIONS_GHC -fno-warn-deprecations #-} -- using Prelude.catch
+{-# LANGUAGE ScopedTypeVariables #-}
-----------------------------------------------------------------------------
-- |
-- Module : Network.HTTP.Base
@@ -123,7 +123,7 @@ import Text.Read.Lex (readDecP)
import Text.ParserCombinators.ReadP
( ReadP, readP_to_S, char, (<++), look, munch )
-import Control.Exception as Exception (IOException)
+import Control.Exception as Exception (catch, IOException)
import qualified Paths_HTTP as Self (version)
import Data.Version (showVersion)
@@ -887,10 +887,10 @@ readTillEmpty2 bufOps readL list =
-- | @catchIO a h@ handles IO action exceptions throughout codebase; version-specific
-- tweaks better go here.
catchIO :: IO a -> (IOException -> IO a) -> IO a
-catchIO a h = Prelude.catch a h
+catchIO a h = Exception.catch a h
catchIO_ :: IO a -> IO a -> IO a
-catchIO_ a h = Prelude.catch a (const h)
+catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h)
responseParseError :: String -> String -> Result a
responseParseError loc v = failWith (ErrorParse (loc ++ ' ':v))
@@ -1,4 +1,3 @@
-{-# OPTIONS_GHC -fno-warn-deprecations #-} -- using Prelude.catch
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
@@ -23,6 +22,7 @@ module Network.HTTP.Proxy
import Control.Monad ( when, mplus, join, liftM2)
+import Network.HTTP.Base ( catchIO )
import Network.HTTP.Utils ( dropWhileTail, chopAtDelim )
import Network.HTTP.Auth
import Network.URI
@@ -87,7 +87,7 @@ registryProxyLoc = (hive, path)
-- read proxy settings from the windows registry; this is just a best
-- effort and may not work on all setups.
-registryProxyString = Prelude.catch
+registryProxyString = catchIO
(bracket (uncurry regOpenKey registryProxyLoc) regCloseKey $ \hkey -> do
enable <- fmap toBool $ regQueryValueDWORD hkey "ProxyEnable"
if enable
@@ -1,4 +1,3 @@
-{-# OPTIONS_GHC -fno-warn-deprecations #-} -- using Prelude.catch
{-# OPTIONS_GHC -fno-warn-orphans #-}
-----------------------------------------------------------------------------
-- |
@@ -37,7 +36,7 @@ import Network.Socket
import Network.HTTP.Base ( catchIO )
import Control.Monad (liftM)
import Control.Exception as Exception (IOException)
-import System.IO.Error (catch, isEOFError)
+import System.IO.Error (isEOFError)
-- | Exception handler for socket operations.
handleSocketError :: Socket -> IOException -> IO (Result a)
@@ -51,7 +50,7 @@ handleSocketError sk e =
myrecv :: Socket -> Int -> IO String
myrecv sock len =
let handler e = if isEOFError e then return [] else ioError e
- in System.IO.Error.catch (recv sock len) handler
+ in catchIO (recv sock len) handler
instance Stream Socket where
readBlock sk n = readBlockSocket sk n
View
@@ -1,4 +1,3 @@
-{-# OPTIONS_GHC -fno-warn-deprecations #-} -- using Prelude.catch
{-# LANGUAGE TypeSynonymInstances #-}
-----------------------------------------------------------------------------
-- |
@@ -303,7 +302,7 @@ isConnectedTo (Connection conn) endPoint = do
ConnClosed -> print "aa" >> return False
_
| connEndPoint v == endPoint ->
- catch (getPeerName (connSock v) >> return True) (const $ return False)
+ catchIO (getPeerName (connSock v) >> return True) (const $ return False)
| otherwise -> return False
isTCPConnectedTo :: HandleStream ty -> EndPoint -> IO Bool
@@ -313,7 +312,7 @@ isTCPConnectedTo conn endPoint = do
ConnClosed -> return False
_
| connEndPoint v == endPoint ->
- catch (getPeerName (connSock v) >> return True) (const $ return False)
+ catchIO (getPeerName (connSock v) >> return True) (const $ return False)
| otherwise -> return False
readBlockBS :: HStream a => HandleStream a -> Int -> IO (Result a)
@@ -365,18 +364,18 @@ bufferGetBlock ref n = onNonClosedDo ref $ \ conn -> do
modifyMVar_ (getRef ref) (\ co -> return co{connInput=Just b})
return (return a)
_ -> do
- Prelude.catch (buf_hGet (connBuffer conn) (connHandle conn) n >>= return.return)
- (\ e ->
+ catchIO (buf_hGet (connBuffer conn) (connHandle conn) n >>= return.return)
+ (\ e ->
if isEOFError e
then do
- when (connCloseEOF conn) $ catch (closeQuick ref) (\ _ -> return ())
+ when (connCloseEOF conn) $ catchIO (closeQuick ref) (\ _ -> return ())
return (return (buf_empty (connBuffer conn)))
else return (failMisc (show e)))
bufferPutBlock :: BufferOp a -> Handle -> a -> IO (Result ())
bufferPutBlock ops h b =
- Prelude.catch (buf_hPut ops h b >> hFlush h >> return (return ()))
- (\ e -> return (failMisc (show e)))
+ catchIO (buf_hPut ops h b >> hFlush h >> return (return ()))
+ (\ e -> return (failMisc (show e)))
bufferReadLine :: HStream a => HandleStream a -> IO (Result a)
bufferReadLine ref = onNonClosedDo ref $ \ conn -> do
@@ -386,13 +385,13 @@ bufferReadLine ref = onNonClosedDo ref $ \ conn -> do
let (newl,b1) = buf_splitAt (connBuffer conn) 1 b0
modifyMVar_ (getRef ref) (\ co -> return co{connInput=Just b1})
return (return (buf_append (connBuffer conn) a newl))
- _ -> Prelude.catch
+ _ -> catchIO
(buf_hGetLine (connBuffer conn) (connHandle conn) >>=
return . return . appendNL (connBuffer conn))
(\ e ->
if isEOFError e
then do
- when (connCloseEOF conn) $ catch (closeQuick ref) (\ _ -> return ())
+ when (connCloseEOF conn) $ catchIO (closeQuick ref) (\ _ -> return ())
return (return (buf_empty (connBuffer conn)))
else return (failMisc (show e)))
where

0 comments on commit 287505c

Please sign in to comment.