diff --git a/shelly.cabal b/shelly.cabal
--- a/shelly.cabal
+++ b/shelly.cabal
@@ -1,6 +1,6 @@
 Name:       shelly
 
-Version:     1.5.1.1
+Version:     1.5.2
 Synopsis:    shell-like (systems) programming in Haskell
 
 Description: Shelly provides convenient systems programming in Haskell,
diff --git a/src/Shelly.hs b/src/Shelly.hs
--- a/src/Shelly.hs
+++ b/src/Shelly.hs
@@ -263,24 +263,27 @@
 transferFoldHandleLines :: a -> FoldCallback a -> Handle -> Handle -> IO a
 transferFoldHandleLines start foldLine readHandle writeHandle = go start
   where
-    catchIOErrors action = catchIOError
-                   (fmap Just action)
-                   (\e -> if isEOFError e || isIllegalOperation e -- handle was closed
-                           then return Nothing
-                           else ioError e)
     go acc = do
-        mLine <- catchIOErrors (TIO.hGetLine readHandle)
+        mLine <- filterIOErrors $ TIO.hGetLine readHandle
         case mLine of
             Nothing -> return acc
             Just line -> TIO.hPutStrLn writeHandle line >> go (foldLine acc line)
 
+filterIOErrors :: IO a -> IO (Maybe a)
+filterIOErrors action = catchIOError
+               (fmap Just action)
+               (\e -> if isEOFError e || isIllegalOperation e -- handle was closed
+                       then return Nothing
+                       else ioError e)
+
 foldHandleLines :: a -> FoldCallback a -> Handle -> IO a
 foldHandleLines start foldLine readHandle = go start
   where
     go acc = do
-      line <- TIO.hGetLine readHandle
-      go $ foldLine acc line
-     `catchany` \_ -> return acc
+      mLine <- filterIOErrors $ TIO.hGetLine readHandle
+      case mLine of
+        Nothing -> return acc
+        Just line -> go $ foldLine acc line
 
 -- | same as 'trace', but use it combinator style
 tag :: Sh a -> Text -> Sh a
@@ -310,7 +313,7 @@
           -- windows looks in extra places besides the PATH, so just give
           -- up even if the behavior is not properly specified anymore
           --
-          -- non-Windows < 7.6 has a bug for read-only file systems
+          -- non-Windows < 7.8 has a bug for read-only file systems
           -- https://github.com/yesodweb/Shelly.hs/issues/56
           -- it would be better to specifically detect that bug
 #if defined(mingw32_HOST_OS) || (defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 708)
