Commit 4d308c04 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Adjust behaviour of reportBuildFailures

Make sure it consistently uses stderr, rather than a mixture of stdout
and stderr. Also rename it to dieOnBuildFailure to make it clear that
it is fatal in the case of build failures.

In general we report build failures in two steps: header plus build log
for each failing package, then a final die exception with summary.
Previously the build log step was reported to stdout whereas the die
exception message gets reported to stderr. So we switch that to use
new dieMsg and dieMsgNoWrap utils so that it all goes to stderr. Also,
like die, these are reported irrespective of the verbosity.

This is more or less just a workaround for the fact that we do not yet
have a nice structured/formatted error mechanism that would allow us to
throw just the one error in this case.
parent 45a6d13a
......@@ -26,6 +26,7 @@ module Distribution.Simple.Utils (
-- * logging and errors
dieMsg, dieMsgNoWrap,
topHandler, topHandlerWith,
warn, notice, noticeNoWrap, setupMessage, info, debug,
debugNoWrap, chattyTry,
......@@ -333,6 +334,28 @@ hPutCallStackPrefix h verbosity = withFrozenCallStack $ do
when (isVerboseCallStack verbosity) $
hPutStr h ("----\n" ++ prettyCallStack callStack ++ "\n")
-- | This can be used to help produce formatted messages as part of a fatal
-- error condition, prior to using 'die' or 'exitFailure'.
-- For fatal conditions we normally simply use 'die' which throws an
-- exception. Sometimes however 'die' is not sufficiently flexible to
-- produce the desired output.
-- Like 'die', these messages are always displayed on @stderr@, irrespective
-- of the 'Verbosity' level.
dieMsg :: String -> NoCallStackIO ()
dieMsg msg = do
hFlush stdout
hPutStr stderr (wrapText msg)
-- | As 'dieMsg' but with pre-formatted text.
dieMsgNoWrap :: String -> NoCallStackIO ()
dieMsgNoWrap msg = do
hFlush stdout
hPutStr stderr msg
-- | Non fatal conditions that may be indicative of an error or problem.
-- We display these at the 'normal' verbosity level.
......@@ -54,7 +54,7 @@ module Distribution.Client.ProjectOrchestration (
-- * Post build actions
) where
import Distribution.Client.ProjectConfig
......@@ -82,8 +82,9 @@ import Distribution.Simple.Setup (HaddockFlags)
import qualified Distribution.Simple.Setup as Setup
import Distribution.Simple.Command (commandShowOptions)
import Distribution.Simple.Utils (die, info, notice, noticeNoWrap
import Distribution.Simple.Utils
( die, dieMsg, dieMsgNoWrap, info
, notice, noticeNoWrap, debug )
import Distribution.Verbosity
import Distribution.Text
......@@ -91,7 +92,6 @@ import qualified Data.Monoid as Mon
import qualified Data.Set as Set
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.List
import Data.Maybe
import Data.Either
......@@ -254,8 +254,9 @@ runProjectPostBuildPhase verbosity ProjectBuildContext {..} buildOutcomes = do
-- - delete stale lib registrations
-- - delete stale package dirs
-- Report any build failures
reportBuildFailures verbosity elaboratedPlan buildOutcomes
-- Finally if there were any build failures then report them and throw
-- an exception to terminate the program
dieOnBuildFailures verbosity elaboratedPlan buildOutcomes
-- Note that it is a deliberate design choice that the 'buildTargets' is
-- not passed to phase 1, and the various bits of input config is not
......@@ -587,8 +588,11 @@ printPlan verbosity
showMonitorChangedReason MonitorCorruptCache = "cannot read state cache"
reportBuildFailures :: Verbosity -> ElaboratedInstallPlan -> BuildOutcomes -> IO ()
reportBuildFailures verbosity plan buildOutcomes
-- | If there are build failures then report them and throw an exception.
dieOnBuildFailures :: Verbosity
-> ElaboratedInstallPlan -> BuildOutcomes -> IO ()
dieOnBuildFailures verbosity plan buildOutcomes
| null failures = return ()
| isSimpleCase = exitFailure
......@@ -596,10 +600,10 @@ reportBuildFailures verbosity plan buildOutcomes
| otherwise = do
-- For failures where we have a build log, print the log plus a header
[ do notice verbosity $
[ do dieMsg $
'\n' : renderFailureDetail False pkg reason
++ "\nBuild log ( " ++ logfile ++ " ):"
BS.readFile logfile >>= BS.putStrLn
readFile logfile >>= dieMsgNoWrap
| verbosity >= normal
, (pkg, ShowBuildSummaryAndLog reason logfile)
<- failuresClassification
Markdown is supported
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