on master help sign in
Produce a non-zero exit code on Task errors
49f58cfEvan Czaplicki
builder/src/Reporting/Progress/Terminal.hs+4−4
@@ -9,7 +9,7 @@ module Reporting.Progress.Terminal
9import Control.Concurrent (forkIO)
9import Control.Concurrent (forkIO)
10import Control.Concurrent.Chan (Chan, newChan, readChan)
10import Control.Concurrent.Chan (Chan, newChan, readChan)
11import Control.Concurrent.MVar (newEmptyMVar, putMVar)
11import Control.Concurrent.MVar (newEmptyMVar, putMVar)
12−import qualified System.Info as System
12+import qualified System.Info as Info
13import System.IO (hFlush, hPutStr, stdout)
13import System.IO (hFlush, hPutStr, stdout)
14import qualified Elm.Package as Pkg
14import qualified Elm.Package as Pkg
15import Elm.Package (Name, Version)
15import Elm.Package (Name, Version)
@@ -212,19 +212,19 @@ makeBullet name version outcome =
212goodMark :: D.Doc
212goodMark :: D.Doc
213goodMark =
213goodMark =
214 D.green $
214 D.green $
215− if System.os == "mingw32" then "+" else "●"
215+ if Info.os == "mingw32" then "+" else "●"
216
216
217
217
218badMark :: D.Doc
218badMark :: D.Doc
219badMark =
219badMark =
220 D.red $
220 D.red $
221− if System.os == "mingw32" then "X" else "✗"
221+ if Info.os == "mingw32" then "X" else "✗"
222
222
223
223
224waitingMark :: D.Doc
224waitingMark :: D.Doc
225waitingMark =
225waitingMark =
226 D.dullyellow $
226 D.dullyellow $
227− if System.os == "mingw32" then "-" else "→"
227+ if Info.os == "mingw32" then "-" else "→"
228
228
229
229
230
230
builder/src/Reporting/Task.hs+18−5
@@ -1,6 +1,10 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Task
2module Reporting.Task
3− ( Task, Task_, run, throw, mapError
3+ ( Task, Task_
4+ , try
5+ , run
6+ , throw
7+ , mapError
4 , Env
8 , Env
5 , getPackageCacheDir
9 , getPackageCacheDir
6 , getPackageCacheDirFor
10 , getPackageCacheDirFor
@@ -23,7 +27,8 @@ import Control.Monad.Reader (ReaderT, runReaderT, ask, asks)
23import Control.Monad.Trans (liftIO)
27import Control.Monad.Trans (liftIO)
24import qualified Network.HTTP.Client as Http
28import qualified Network.HTTP.Client as Http
25import qualified Network.HTTP.Client.TLS as Http
29import 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
27import System.FilePath ((</>))
32import System.FilePath ((</>))
28import qualified System.IO as IO
33import qualified System.IO as IO
29
34
@@ -55,8 +60,8 @@ data Env =
55 }
60 }
56
61
57
62
58−run :: Progress.Reporter -> Task a -> IO (Maybe a)
63+try :: Progress.Reporter -> Task a -> IO (Maybe a)
59−run (Progress.Reporter tell end) task =
64+try (Progress.Reporter tell end) task =
60 do root <- PerUserCache.getPackageRoot
65 do root <- PerUserCache.getPackageRoot
61 pool <- initPool 4
66 pool <- initPool 4
62 httpManager <- Http.newManager Http.tlsManagerSettings
67 httpManager <- Http.newManager Http.tlsManagerSettings
@@ -72,6 +77,14 @@ run (Progress.Reporter tell end) task =
72 return (Just answer)
77 return (Just answer)
73
78
74
79
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+
75throw :: e -> Task_ e a
88throw :: e -> Task_ e a
76throw =
89throw =
77 throwError
90 throwError
@@ -95,7 +108,7 @@ getPackageCacheDirFor :: Name -> Version -> Task_ e FilePath
95getPackageCacheDirFor name version =
108getPackageCacheDirFor name version =
96 do cacheDir <- getPackageCacheDir
109 do cacheDir <- getPackageCacheDir
97 let dir = cacheDir </> Pkg.toFilePath name </> Pkg.versionToString version
110 let dir = cacheDir </> Pkg.toFilePath name </> Pkg.versionToString version
98− liftIO (createDirectoryIfMissing True dir)
111+ liftIO (Dir.createDirectoryIfMissing True dir)
99 return dir
112 return dir
100
113
101
114
ui/terminal/src/Bump.hs+1−3
@@ -1,8 +1,6 @@
1module Bump (run) where
1module Bump (run) where
2
2
3
3
4−import Control.Monad (void)
5−
6import qualified Elm.Bump as Bump
4import qualified Elm.Bump as Bump
7import qualified Elm.Project as Project
5import qualified Elm.Project as Project
8import qualified Reporting.Task as Task
6import qualified Reporting.Task as Task
@@ -16,6 +14,6 @@ import qualified Reporting.Progress.Terminal as Terminal
16run :: () -> () -> IO ()
14run :: () -> () -> IO ()
17run () () =
15run () () =
18 do reporter <- Terminal.create
16 do reporter <- Terminal.create
19− void $ Task.run reporter $
17+ Task.run reporter $
20 do summary <- Project.getRoot
18 do summary <- Project.getRoot
21 Bump.bump summary
19 Bump.bump summary
ui/terminal/src/Develop.hs+1−1
@@ -166,7 +166,7 @@ compileToHtmlBuilder file =
166 let reporter = Progress.Reporter (\_ -> return ()) (putMVar mvar1)
166 let reporter = Progress.Reporter (\_ -> return ()) (putMVar mvar1)
167 let output = Just (Output.HtmlBuilder mvar2)
167 let output = Just (Output.HtmlBuilder mvar2)
168
168
169− void $ Task.run reporter $
169+ void $ Task.try reporter $
170 do summary <- Project.getRoot
170 do summary <- Project.getRoot
171 Project.compile Output.Dev Output.Client output Nothing summary [file]
171 Project.compile Output.Dev Output.Client output Nothing summary [file]
172
172
ui/terminal/src/Develop/Generate/Index.hs+1−1
@@ -90,7 +90,7 @@ getFlags root pwd =
90 readme <- getReadme pwd
90 readme <- getReadme pwd
91
91
92 maybeSummary <-
92 maybeSummary <-
93− Task.run Progress.silentReporter $
93+ Task.try Progress.silentReporter $
94 Verify.verify root =<< Project.read "elm.json"
94 Verify.verify root =<< Project.read "elm.json"
95
95
96 return $
96 return $
ui/terminal/src/Develop/StaticFiles/Build.hs+1−2
@@ -6,7 +6,6 @@ module Develop.StaticFiles.Build
6 where
6 where
7
7
8
8
9−import Control.Monad (void)
10import qualified Data.ByteString as BS
9import qualified Data.ByteString as BS
11import qualified System.Directory as Dir
10import qualified System.Directory as Dir
12import System.FilePath ((</>))
11import System.FilePath ((</>))
@@ -34,7 +33,7 @@ compile :: IO BS.ByteString
34compile =
33compile =
35 Dir.withCurrentDirectory ("ui" </> "browser") $
34 Dir.withCurrentDirectory ("ui" </> "browser") $
36 do reporter <- Terminal.create
35 do reporter <- Terminal.create
37− void $ Task.run reporter $
36+ Task.run reporter $
38 do summary <- Project.getRoot
37 do summary <- Project.getRoot
39 let jsOutput = Just (Output.JavaScript Nothing tempFileName)
38 let jsOutput = Just (Output.JavaScript Nothing tempFileName)
40 Project.compile Output.Prod Output.Client jsOutput Nothing summary rootPaths
39 Project.compile Output.Prod Output.Client jsOutput Nothing summary rootPaths
ui/terminal/src/Diff.hs+1−3
@@ -2,8 +2,6 @@
2module Diff (run) where
2module Diff (run) where
3
3
4
4
5−import Control.Monad (void)
6−
7import qualified Elm.Diff as Diff
5import qualified Elm.Diff as Diff
8import qualified Reporting.Task as Task
6import qualified Reporting.Task as Task
9import qualified Reporting.Progress.Terminal as Terminal
7import qualified Reporting.Progress.Terminal as Terminal
@@ -16,4 +14,4 @@ import qualified Reporting.Progress.Terminal as Terminal
16run :: Diff.Args -> () -> IO ()
14run :: Diff.Args -> () -> IO ()
17run args () =
15run args () =
18 do reporter <- Terminal.create
16 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 @@
1module Install (run) where
1module Install (run) where
2
2
3
3
4−import Control.Monad (void)
5−
6import qualified Elm.Install as Install
4import qualified Elm.Install as Install
7import qualified Elm.Package as Pkg
5import qualified Elm.Package as Pkg
8import qualified Reporting.Task as Task
6import qualified Reporting.Task as Task
@@ -16,5 +14,4 @@ import qualified Reporting.Progress.Terminal as Terminal
16run :: Pkg.Name -> () -> IO ()
14run :: Pkg.Name -> () -> IO ()
17run pkg () =
15run pkg () =
18 do reporter <- Terminal.create
16 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
8 where
8 where
9
9
10
10
11−import Control.Monad (void)
12import qualified System.FilePath as FP
11import qualified System.FilePath as FP
13
12
14import qualified Elm.Project as Project
13import qualified Elm.Project as Project
@@ -39,7 +38,7 @@ data Flags =
39run :: [FilePath] -> Flags -> IO ()
38run :: [FilePath] -> Flags -> IO ()
40run paths (Flags debug optimize output report docs) =
39run paths (Flags debug optimize output report docs) =
41 do reporter <- toReporter report
40 do reporter <- toReporter report
42− void $ Task.run reporter $
41+ Task.run reporter $
43 do mode <- toMode debug optimize
42 do mode <- toMode debug optimize
44 summary <- Project.getRoot
43 summary <- Project.getRoot
45 Project.compile mode Output.Client output docs summary paths
44 Project.compile mode Output.Client output docs summary paths
ui/terminal/src/Publish.hs+1−3
@@ -1,8 +1,6 @@
1module Publish (run) where
1module Publish (run) where
2
2
3
3
4−import Control.Monad (void)
5−
6import qualified Elm.Project as Project
4import qualified Elm.Project as Project
7import qualified Elm.Publish as Publish
5import qualified Elm.Publish as Publish
8import qualified Reporting.Task as Task
6import qualified Reporting.Task as Task
@@ -16,6 +14,6 @@ import qualified Reporting.Progress.Terminal as Terminal
16run :: () -> () -> IO ()
14run :: () -> () -> IO ()
17run () () =
15run () () =
18 do reporter <- Terminal.create
16 do reporter <- Terminal.create
19− void $ Task.run reporter $
17+ Task.run reporter $
20 do summary <- Project.getRoot
18 do summary <- Project.getRoot
21 Publish.publish summary
19 Publish.publish summary
ui/terminal/src/Repl.hs+1−1
@@ -150,7 +150,7 @@ data Output = None | Def N.Name | Expr Text.Text
150
150
151interpret :: Output -> State -> Runner (Maybe a)
151interpret :: Output -> State -> Runner (Maybe a)
152interpret def state =
152interpret def state =
153− do result <- liftIO $ Task.run Repl.reporter $ compile def state
153+ do result <- liftIO $ Task.try Repl.reporter $ compile def state
154
154
155 case result of
155 case result of
156 Nothing ->
156 Nothing ->