on master help sign in
Produce a non-zero exit code on Task errors
commit49f58cf786f55deee7e423e1d1c4304da245856b authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 17 Apr 2018, 18:31 (9 years ago) parent3ff1dd3
11 files changed+31−29
builder/src/Reporting/Progress/Terminal.hs+4−4 builder/src/Reporting/Task.hs+18−5 ui/terminal/src/Bump.hs+1−3 ui/terminal/src/Develop.hs+1−1 ui/terminal/src/Develop/Generate/Index.hs+1−1 ui/terminal/src/Develop/StaticFiles/Build.hs+1−2 ui/terminal/src/Diff.hs+1−3 ui/terminal/src/Install.hs+1−4 ui/terminal/src/Make.hs+1−2 ui/terminal/src/Publish.hs+1−3 ui/terminal/src/Repl.hs+1−1
builder/src/Reporting/Progress/Terminal.hs+4−4
@@ -9,7 +9,7 @@ module Reporting.Progress.Terminal
99import Control.Concurrent (forkIO)
1010import Control.Concurrent.Chan (Chan, newChan, readChan)
1111import Control.Concurrent.MVar (newEmptyMVar, putMVar)
12−import qualified System.Info as System
12+import qualified System.Info as Info
1313import System.IO (hFlush, hPutStr, stdout)
1414import qualified Elm.Package as Pkg
1515import Elm.Package (Name, Version)
@@ -212,19 +212,19 @@ makeBullet name version outcome =
212212goodMark :: D.Doc
213213goodMark =
214214 D.green $
215− if System.os == "mingw32" then "+" else "●"
215+ if Info.os == "mingw32" then "+" else "●"
216216
217217
218218badMark :: D.Doc
219219badMark =
220220 D.red $
221− if System.os == "mingw32" then "X" else "✗"
221+ if Info.os == "mingw32" then "X" else "✗"
222222
223223
224224waitingMark :: D.Doc
225225waitingMark =
226226 D.dullyellow $
227− if System.os == "mingw32" then "-" else "→"
227+ if Info.os == "mingw32" then "-" else "→"
228228
229229
230230
builder/src/Reporting/Task.hs+18−5
@@ -1,6 +1,10 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Reporting.Task
3− ( Task, Task_, run, throw, mapError
3+ ( Task, Task_
4+ , try
5+ , run
6+ , throw
7+ , mapError
48 , Env
59 , getPackageCacheDir
610 , getPackageCacheDirFor
@@ -23,7 +27,8 @@ import Control.Monad.Reader (ReaderT, runReaderT, ask, asks)
2327import Control.Monad.Trans (liftIO)
2428import qualified Network.HTTP.Client as Http
2529import qualified Network.HTTP.Client.TLS as Http
26−import System.Directory (createDirectoryIfMissing)
30+import qualified System.Directory as Dir
31+import qualified System.Exit as Exit
2732import System.FilePath ((</>))
2833import qualified System.IO as IO
2934
@@ -55,8 +60,8 @@ data Env =
5560 }
5661
5762
58−run :: Progress.Reporter -> Task a -> IO (Maybe a)
59−run (Progress.Reporter tell end) task =
63+try :: Progress.Reporter -> Task a -> IO (Maybe a)
64+try (Progress.Reporter tell end) task =
6065 do root <- PerUserCache.getPackageRoot
6166 pool <- initPool 4
6267 httpManager <- Http.newManager Http.tlsManagerSettings
@@ -72,6 +77,14 @@ run (Progress.Reporter tell end) task =
7277 return (Just answer)
7378
7479
80+run :: Progress.Reporter -> Task a -> IO ()
81+run reporter task =
82+ do maybeAnswer <- try reporter task
83+ case maybeAnswer of
84+ Nothing -> Exit.exitFailure
85+ Just _ -> return ()
86+
87+
7588throw :: e -> Task_ e a
7689throw =
7790 throwError
@@ -95,7 +108,7 @@ getPackageCacheDirFor :: Name -> Version -> Task_ e FilePath
95108getPackageCacheDirFor name version =
96109 do cacheDir <- getPackageCacheDir
97110 let dir = cacheDir </> Pkg.toFilePath name </> Pkg.versionToString version
98− liftIO (createDirectoryIfMissing True dir)
111+ liftIO (Dir.createDirectoryIfMissing True dir)
99112 return dir
100113
101114
ui/terminal/src/Bump.hs+1−3
@@ -1,8 +1,6 @@
11module Bump (run) where
22
33
4−import Control.Monad (void)
5−
64import qualified Elm.Bump as Bump
75import qualified Elm.Project as Project
86import qualified Reporting.Task as Task
@@ -16,6 +14,6 @@ import qualified Reporting.Progress.Terminal as Terminal
1614run :: () -> () -> IO ()
1715run () () =
1816 do reporter <- Terminal.create
19− void $ Task.run reporter $
17+ Task.run reporter $
2018 do summary <- Project.getRoot
2119 Bump.bump summary
ui/terminal/src/Develop.hs+1−1
@@ -166,7 +166,7 @@ compileToHtmlBuilder file =
166166 let reporter = Progress.Reporter (\_ -> return ()) (putMVar mvar1)
167167 let output = Just (Output.HtmlBuilder mvar2)
168168
169− void $ Task.run reporter $
169+ void $ Task.try reporter $
170170 do summary <- Project.getRoot
171171 Project.compile Output.Dev Output.Client output Nothing summary [file]
172172
ui/terminal/src/Develop/Generate/Index.hs+1−1
@@ -90,7 +90,7 @@ getFlags root pwd =
9090 readme <- getReadme pwd
9191
9292 maybeSummary <-
93− Task.run Progress.silentReporter $
93+ Task.try Progress.silentReporter $
9494 Verify.verify root =<< Project.read "elm.json"
9595
9696 return $
ui/terminal/src/Develop/StaticFiles/Build.hs+1−2
@@ -6,7 +6,6 @@ module Develop.StaticFiles.Build
66 where
77
88
9−import Control.Monad (void)
109import qualified Data.ByteString as BS
1110import qualified System.Directory as Dir
1211import System.FilePath ((</>))
@@ -34,7 +33,7 @@ compile :: IO BS.ByteString
3433compile =
3534 Dir.withCurrentDirectory ("ui" </> "browser") $
3635 do reporter <- Terminal.create
37− void $ Task.run reporter $
36+ Task.run reporter $
3837 do summary <- Project.getRoot
3938 let jsOutput = Just (Output.JavaScript Nothing tempFileName)
4039 Project.compile Output.Prod Output.Client jsOutput Nothing summary rootPaths
ui/terminal/src/Diff.hs+1−3
@@ -2,8 +2,6 @@
22module Diff (run) where
33
44
5−import Control.Monad (void)
6−
75import qualified Elm.Diff as Diff
86import qualified Reporting.Task as Task
97import qualified Reporting.Progress.Terminal as Terminal
@@ -16,4 +14,4 @@ import qualified Reporting.Progress.Terminal as Terminal
1614run :: Diff.Args -> () -> IO ()
1715run args () =
1816 do reporter <- Terminal.create
19− void $ Task.run reporter $ Diff.diff args
17+ Task.run reporter $ Diff.diff args
ui/terminal/src/Install.hs+1−4
@@ -1,8 +1,6 @@
11module Install (run) where
22
33
4−import Control.Monad (void)
5−
64import qualified Elm.Install as Install
75import qualified Elm.Package as Pkg
86import qualified Reporting.Task as Task
@@ -16,5 +14,4 @@ import qualified Reporting.Progress.Terminal as Terminal
1614run :: Pkg.Name -> () -> IO ()
1715run pkg () =
1816 do reporter <- Terminal.create
19− void $ Task.run reporter $
20− Install.install pkg
17+ Task.run reporter $ Install.install pkg
ui/terminal/src/Make.hs+1−2
@@ -8,7 +8,6 @@ module Make
88 where
99
1010
11−import Control.Monad (void)
1211import qualified System.FilePath as FP
1312
1413import qualified Elm.Project as Project
@@ -39,7 +38,7 @@ data Flags =
3938run :: [FilePath] -> Flags -> IO ()
4039run paths (Flags debug optimize output report docs) =
4140 do reporter <- toReporter report
42− void $ Task.run reporter $
41+ Task.run reporter $
4342 do mode <- toMode debug optimize
4443 summary <- Project.getRoot
4544 Project.compile mode Output.Client output docs summary paths
ui/terminal/src/Publish.hs+1−3
@@ -1,8 +1,6 @@
11module Publish (run) where
22
33
4−import Control.Monad (void)
5−
64import qualified Elm.Project as Project
75import qualified Elm.Publish as Publish
86import qualified Reporting.Task as Task
@@ -16,6 +14,6 @@ import qualified Reporting.Progress.Terminal as Terminal
1614run :: () -> () -> IO ()
1715run () () =
1816 do reporter <- Terminal.create
19− void $ Task.run reporter $
17+ Task.run reporter $
2018 do summary <- Project.getRoot
2119 Publish.publish summary
ui/terminal/src/Repl.hs+1−1
@@ -150,7 +150,7 @@ data Output = None | Def N.Name | Expr Text.Text
150150
151151interpret :: Output -> State -> Runner (Maybe a)
152152interpret def state =
153− do result <- liftIO $ Task.run Repl.reporter $ compile def state
153+ do result <- liftIO $ Task.try Repl.reporter $ compile def state
154154
155155 case result of
156156 Nothing ->