Add comments to "OPTIONS_GHC -fno-warn-orphans" pragmas
[ghc-hetmet.git] / libraries / bin-package-db / Distribution / InstalledPackageInfo / Binary.hs
index 212c8f9..af83148 100644 (file)
@@ -1,4 +1,8 @@
 {-# LANGUAGE RecordWildCards, TypeSynonymInstances, StandaloneDeriving, GeneralizedNewtypeDeriving #-}
+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
+-- This module deliberately defines orphan instances for now. Should
+-- become unnecessary once we move to using the binary package properly:
+{-# OPTIONS_GHC -fno-warn-orphans #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Distribution.InstalledPackageInfo.Binary
@@ -14,13 +18,28 @@ module Distribution.InstalledPackageInfo.Binary (
   ) where
 
 import Distribution.Version
-import Distribution.Package
+import Distribution.Package hiding (depends)
 import Distribution.License
 import Distribution.InstalledPackageInfo as IPI
 import Data.Binary as Bin
+import Control.Exception as Exception
 
 readBinPackageDB :: Binary m => FilePath -> IO [InstalledPackageInfo_ m]
-readBinPackageDB file = Bin.decodeFile file
+readBinPackageDB file
+    = do xs <- Bin.decodeFile file
+         _ <- Exception.evaluate $ length xs
+         return xs
+      `catchUserError`
+      (\err -> error ("While parsing " ++ show file ++ ": " ++ err))
+
+catchUserError :: IO a -> (String -> IO a) -> IO a
+#ifdef BASE3
+catchUserError io f = io `Exception.catch` \e -> case e of
+                                                 ErrorCall err -> f err
+                                                 _ -> throw e
+#else
+catchUserError io f = io `Exception.catch` \(ErrorCall err) -> f err
+#endif
 
 writeBinPackageDB :: Binary m => FilePath -> [InstalledPackageInfo_ m] -> IO ()
 writeBinPackageDB file ipis = Bin.encodeFile file ipis
@@ -123,7 +142,7 @@ instance Binary License where
       5 -> return PublicDomain
       6 -> return AllRightsReserved
       7 -> return OtherLicense
-      8 -> do str <- get; return (UnknownLicense str)
+      _ -> do str <- get; return (UnknownLicense str)
 
 instance Binary Version where
   put v = do put (versionBranch v); put (versionTags v)