Commit 1c8139d8 authored by ijones's avatar ijones
Browse files

improved error handling for multiple installs

When installing multiple packages, don't quit just after the first
error, but rather collect the list of packages that failed to install
continue installing whatever packages we can, and provide an error
message at the end.
parent 05e0dc62
...@@ -14,7 +14,7 @@ module Hackage.Install ...@@ -14,7 +14,7 @@ module Hackage.Install
( install ( install
) where ) where
import Control.Exception (bracket_) import Control.Exception (bracket_, try)
import Control.Monad (when) import Control.Monad (when)
import Data.Monoid (Monoid(mempty)) import Data.Monoid (Monoid(mempty))
import System.Directory (getTemporaryDirectory, createDirectoryIfMissing import System.Directory (getTemporaryDirectory, createDirectoryIfMissing
...@@ -71,7 +71,20 @@ installPackages :: ConfigFlags ...@@ -71,7 +71,20 @@ installPackages :: ConfigFlags
-> Cabal.ConfigFlags -- ^Options which will be passed to every package. -> Cabal.ConfigFlags -- ^Options which will be passed to every package.
-> [(PkgInfo,FlagAssignment)] -- ^ (Package, list of configure options) -> [(PkgInfo,FlagAssignment)] -- ^ (Package, list of configure options)
-> IO () -> IO ()
installPackages cfg configFlags = mapM_ (installPkg cfg configFlags) installPackages cfg configFlags pkgs = do
errorPackages <- installPackagesErrs pkgs []
case errorPackages of
[] -> return ()
pkgs -> do let errorMsg = concat $ "Error: some packages failed to install:"
: ["\n " ++ showPackageId (pkgInfoId x) | (x, _) <- pkgs]
die errorMsg
where installPackagesErrs (pkg:pkgs) errPkgs = do
maybeInstalled <- try (installPkg cfg configFlags pkg)
case maybeInstalled of
Left e -> installPackagesErrs pkgs (pkg:errPkgs)
Right _ -> installPackagesErrs pkgs errPkgs
installPackagesErrs [] ers = return ers
{-| {-|
......
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