summaryrefslogtreecommitdiff
path: root/compiler/main/Packages.lhs
diff options
context:
space:
mode:
authorPaolo Capriotti <p.capriotti@gmail.com>2012-06-04 11:59:25 +0100
committerPaolo Capriotti <p.capriotti@gmail.com>2012-06-04 16:26:07 +0100
commit50fddb2b046605315f903d9b744780497cc978de (patch)
treee0a35cae674ce9ebb30287345a9011d4ad0836d5 /compiler/main/Packages.lhs
parent52d9f09bba0d6ff5a629c5cadf38166bbdce9378 (diff)
downloadhaskell-50fddb2b046605315f903d9b744780497cc978de.tar.gz
Improve error message for invalid package db file (#6133).
Use `reads` instead of `read` to parse package configuration files, and report a meaningful error when the parsing fails.
Diffstat (limited to 'compiler/main/Packages.lhs')
-rw-r--r--compiler/main/Packages.lhs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/main/Packages.lhs b/compiler/main/Packages.lhs
index cdda96193c..42e5cf5557 100644
--- a/compiler/main/Packages.lhs
+++ b/compiler/main/Packages.lhs
@@ -59,6 +59,7 @@ import System.Directory
import System.FilePath as FilePath
import qualified System.FilePath.Posix as FilePath.Posix
import Control.Monad
+import Data.Char (isSpace)
import Data.List as List
import Data.Map (Map)
import qualified Data.Map as Map
@@ -234,7 +235,11 @@ readPackageConfig dflags conf_file = do
"can't find a package database at " ++ conf_file
debugTraceMsg dflags 2 (text "Using package config file:" <+> text conf_file)
str <- readFile conf_file
- return (map installedPackageInfoToPackageConfig $ read str)
+ case reads str of
+ [(configs, rest)]
+ | all isSpace rest -> return (map installedPackageInfoToPackageConfig configs)
+ _ -> ghcError $ InstallationError $
+ "invalid package database file " ++ conf_file
let
top_dir = topDir dflags