Commit 87b444ce authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Cope better with ghc bug #2201, display a better error message

Otherwise it can (and does) really confuse people.
The problem is that the command $ ghc-pkg-6.9 describe '*' --user
returns a non-zero exit code if the user package db is empty.
ghc-pkg intends this exit code to tell us if the query returned
any results (one can use more complex queries as tests) but Cabal
interprets it as failure. Indeed we cannot distinguish it from
any other kind of failure from ghc-pkg.
parent 10128e71
......@@ -98,7 +98,10 @@ import System.Directory ( removeFile, renameFile,
import System.FilePath ( (</>), (<.>), takeExtension,
takeDirectory, replaceExtension, splitExtension )
import System.IO (openFile, IOMode(WriteMode), hClose, hPutStrLn)
import Control.Exception (handle, try)
import Control.Exception as Exception
( Exception(ExitException), catch, handle, try, throwIO )
import System.Exit
( ExitCode(..) )
-- -----------------------------------------------------------------------------
-- Configuring
......@@ -280,6 +283,13 @@ getInstalledPackages' verbosity packagedbs conf
[ do str <- rawSystemProgramStdoutConf verbosity ghcPkgProgram conf
["describe", "*", packageDbGhcPkgFlag packagedb]
`Exception.catch` \exception -> case exception of
ExitException (ExitFailure 1) -> die $
"ghc-pkg describe * failed. If you are using ghc-6.9 "
++ "and have an empty user package database then this "
++ "is probably due to ghc bug #2201. The workaround is to "
++ "register at least one package in the user package db."
_ -> throwIO exception
case parsePackages str of
Left ok -> return (packagedb, ok)
_ -> die "failed to parse output of 'ghc-pkg describe *'"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment