Permalink
Browse files

Merge pull request #3 from acfoltzer/master

catchIOError fix
  • Loading branch information...
2 parents 194329a + 1fd41ab commit c3f566b3275e18985c8cae2d1c5869337e7d1278 @JPMoresmau committed Oct 24, 2012
Showing with 19 additions and 4 deletions.
  1. +10 −3 src/Scion/Packages.hs
  2. +9 −1 src/Scion/PersistentBrowser/Parser.hs
View
@@ -31,7 +31,14 @@ import GHC.Paths
import qualified Control.Exception as Exception
--- This was borrowed from the ghc-pkg source:
+#if __GLASGOW_HASKELL__ < 702
+catchIOError :: IO a -> (IOError -> IO a) -> IO a
+catchIOError = catch
+#else
+import System.IO.Error (catchIOError)
+#endif
+
+-- this was borrowed from the ghc-pkg source:
type InstalledPackageInfoString = InstalledPackageInfo_ String
-- | Types of cabal package databases
@@ -135,7 +142,7 @@ readContents pkgdb =
#if __GLASGOW_HASKELL__ >= 612
-- fix the encoding to UTF-8
hSetEncoding h utf8
- catch (hGetContents h) (\_ -> do
+ catchIOError (hGetContents h) (\_ -> do
-- logInfo $ ioeGetErrorString err
hClose h
h' <- openFile file ReadMode
@@ -169,7 +176,7 @@ readContents pkgdb =
pkgInfoReader :: FilePath
-> IO [InstalledPackageInfo]
pkgInfoReader f =
- catch (
+ catchIOError (
do
pkgStr <- readUTF8File f
let pkgInfo = parseInstalledPackageInfo pkgStr
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Scion.PersistentBrowser.Parser
@@ -24,6 +25,13 @@ import Text.Parsec.Prim (runP)
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Pos (newPos)
+#if __GLASGOW_HASKELL__ < 702
+catchIOError :: IO a -> (IOError -> IO a) -> IO a
+catchIOError = catch
+#else
+import System.IO.Error (catchIOError)
+#endif
+
-- | Parses the contents of a string containing the
-- Hoogle file contents.
parseHoogleString :: String -> BS.ByteString -> Either ParseError (Documented Package)
@@ -37,7 +45,7 @@ parseHoogleFile fname = (withFile fname ReadMode $
\hnd -> do c <- BS.hGetContents hnd
return $ parseHoogleString fname c
)
- `catch`
+ `catchIOError`
(\_ -> return $ Left (newErrorMessage (Message "error reading file")
(newPos fname 0 0)))

0 comments on commit c3f566b

Please sign in to comment.