summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2009-11-29 03:10:29 +0000
committerIan Lynagh <igloo@earth.li>2009-11-29 03:10:29 +0000
commitf9460db84b4eb145d1356435127cce0a1a775c70 (patch)
tree5c545c63f289ebc2f2a0082a5d970a65ede68611 /libraries
parentf41e3ea766c340c49b829eabfdea7c77bda2a95e (diff)
downloadhaskell-f9460db84b4eb145d1356435127cce0a1a775c70.tar.gz
Give more informative error messages
We used to just get ghc: panic! (the 'impossible' happened) (GHC version 6.13.20091128 for x86_64-unknown-linux): too few bytes. Failed reading at byte position 32753 with no indication of what was being parsed.
Diffstat (limited to 'libraries')
-rw-r--r--libraries/bin-package-db/Distribution/InstalledPackageInfo/Binary.hs17
-rw-r--r--libraries/bin-package-db/bin-package-db.cabal14
2 files changed, 28 insertions, 3 deletions
diff --git a/libraries/bin-package-db/Distribution/InstalledPackageInfo/Binary.hs b/libraries/bin-package-db/Distribution/InstalledPackageInfo/Binary.hs
index 0f599298a5..387b78f631 100644
--- a/libraries/bin-package-db/Distribution/InstalledPackageInfo/Binary.hs
+++ b/libraries/bin-package-db/Distribution/InstalledPackageInfo/Binary.hs
@@ -19,9 +19,24 @@ 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
diff --git a/libraries/bin-package-db/bin-package-db.cabal b/libraries/bin-package-db/bin-package-db.cabal
index cc032005e9..fbac32763e 100644
--- a/libraries/bin-package-db/bin-package-db.cabal
+++ b/libraries/bin-package-db/bin-package-db.cabal
@@ -11,11 +11,21 @@ source-repository head
type: darcs
location: http://darcs.haskell.org/ghc
+flag base3
+ default: False
+
Library {
exposed-modules:
Distribution.InstalledPackageInfo.Binary
- build-depends: base >= 3 && < 5,
- binary == 0.5.*,
+ if flag(base3)
+ build-depends: base >= 3 && < 4
+ cpp-options: -DBASE3
+ else
+ build-depends: base >= 4 && < 5
+
+ build-depends: binary == 0.5.*,
Cabal == 1.8.*
+
+ extensions: CPP
}