From 49b31ed73057b49026a36471b18d0a7e297b0ceb Mon Sep 17 00:00:00 2001 From: Duncan Coutts Date: Sun, 26 Jun 2016 23:11:18 +0100 Subject: [PATCH] Annotate exceptions in downloading packages Download errors are now put into the residual install plan, like other build errors. Fixes issue #3387 --- .../Distribution/Client/ProjectBuilding.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cabal-install/Distribution/Client/ProjectBuilding.hs b/cabal-install/Distribution/Client/ProjectBuilding.hs index 4a6a88fe4b3..dc43f29899b 100644 --- a/cabal-install/Distribution/Client/ProjectBuilding.hs +++ b/cabal-install/Distribution/Client/ProjectBuilding.hs @@ -76,7 +76,6 @@ import Data.Maybe import System.FilePath import System.IO import System.Directory -import System.Exit (ExitCode) ------------------------------------------------------------------------------ @@ -669,7 +668,8 @@ rebuildTarget verbosity unexpectedState = error "rebuildTarget: unexpected package status" downloadPhase = do - downsrcloc <- waitAsyncPackageDownload verbosity downloadMap pkg + downsrcloc <- annotateFailure DownloadFailed $ + waitAsyncPackageDownload verbosity downloadMap pkg case downsrcloc of DownloadedTarball tarball -> unpackTarballPhase tarball --TODO: [nice to have] git/darcs repos etc @@ -1261,8 +1261,16 @@ buildInplaceUnpackedPackage verbosity annotateFailure :: (SomeException -> BuildFailure) -> IO a -> IO a annotateFailure annotate action = action `catches` - [ Handler $ \ioe -> handler (ioe :: IOException) - , Handler $ \exit -> handler (exit :: ExitCode) + -- It's not just IOException and ExitCode we have to deal with, there's + -- lots, including exceptions from the hackage-security and tar packages. + -- So we take the strategy of catching everything except async exceptions. + [ +#if MIN_VERSION_base(4,7,0) + Handler $ \async -> throwIO (async :: SomeAsyncException) +#else + Handler $ \async -> throwIO (async :: AsyncException) +#endif + , Handler $ \other -> handler (other :: SomeException) ] where handler :: Exception e => e -> IO a