summaryrefslogtreecommitdiff
path: root/utils/ghc-pkg
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2008-07-30 19:45:08 +0000
committerIan Lynagh <igloo@earth.li>2008-07-30 19:45:08 +0000
commit0c04c63de98877842dddfb5b437983dd9bdad788 (patch)
treeaba3685a6e1113bc90c6b59113ec031dbbb44f96 /utils/ghc-pkg
parentaee2bc2f38e8233011a0d955eb5adac841f0c9b4 (diff)
downloadhaskell-0c04c63de98877842dddfb5b437983dd9bdad788.tar.gz
Fix building with extensible exceptions
Diffstat (limited to 'utils/ghc-pkg')
-rw-r--r--utils/ghc-pkg/Main.hs39
1 files changed, 33 insertions, 6 deletions
diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
index 0f0b9ec054..f310cc6e47 100644
--- a/utils/ghc-pkg/Main.hs
+++ b/utils/ghc-pkg/Main.hs
@@ -465,10 +465,10 @@ getPkgDatabases modify my_flags = do
readParseDatabase :: PackageDBName -> IO (PackageDBName,PackageDB)
readParseDatabase filename = do
- str <- readFile filename `Exception.catch` \_ -> return emptyPackageConfig
+ str <- readFile filename `catchIO` \_ -> return emptyPackageConfig
let packages = map convertPackageInfoIn $ read str
Exception.evaluate packages
- `Exception.catch` \e->
+ `catchError` \e->
die ("error while parsing " ++ filename ++ ": " ++ show e)
return (filename,packages)
@@ -811,20 +811,19 @@ savingOldConfig filename io = Exception.block $ do
ioError err
return False
(do hPutStrLn stdout "done."; io)
- `Exception.catch` \e -> do
+ `onException` do
hPutStr stdout ("WARNING: an error was encountered while writing "
++ "the new configuration.\n")
-- remove any partially complete new version:
- try (removeFile filename)
+ removeFile filename `catchIO` \_ -> return ()
-- and attempt to restore the old one, if we had one:
when restore_on_error $ do
hPutStr stdout "Attempting to restore the old configuration... "
do renameFile oldFile filename
hPutStrLn stdout "done."
- `catch` \err -> hPutStrLn stdout ("Failed: " ++ show err)
+ `catchIO` \err -> hPutStrLn stdout ("Failed: " ++ show err)
-- Note the above renameFile sometimes fails on Windows with
-- "permission denied", I have no idea why --SDM.
- Exception.throwIO e
-----------------------------------------------------------------------------
-- Sanity-check a new package config, and automatically build GHCi libs
@@ -1119,3 +1118,31 @@ installSignalHandlers = do
isInfixOf :: (Eq a) => [a] -> [a] -> Bool
isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack)
#endif
+
+catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
+#if __GLASGOW_HASKELL__ >= 609
+catchIO = Exception.catch
+#else
+catchIO io handler = io `Exception.catch` handler'
+ where handler' (Exception.IOException ioe) = handler ioe
+ handler' e = Exception.throw e
+#endif
+
+catchError :: IO a -> (String -> IO a) -> IO a
+#if __GLASGOW_HASKELL__ >= 609
+catchError io handler = io `Exception.catch` handler'
+ where handler' (Exception.ErrorCall err) = handler err
+#else
+catchError io handler = io `Exception.catch` handler'
+ where handler' (Exception.ErrorCall err) = handler err
+ handler' e = Exception.throw e
+#endif
+
+onException :: IO a -> IO () -> IO a
+#if __GLASGOW_HASKELL__ >= 609
+onException = Exception.onException
+#else
+onException io what = io `Exception.catch` \e -> do what
+ Exception.throw e
+#endif
+