on master help sign in
Switch Error to Exit in builder/

The idea is that compiler/ may produce a bunch of errors. There can be zero or more of these. That does not mean we have to give up immediately. In contrast, builder/ may exit at some point. Something goes wrong and we just have to stop everything. An exit may contain errors. This is intended to help with turning exits into JSON in a consistent way.

commit1063c93440fb76f4489cf22ffb6681eb6baceb2f authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 27 Mar 2018, 17:57 (9 years ago) parent9b80d4e
30 files changed+240−215
builder/src/Deps/Explorer.hs+3−3 builder/src/Deps/Get.hs+4−4 builder/src/Deps/Verify.hs+5−5 builder/src/Deps/Website.hs+4−4 builder/src/Elm/Bump.hs+5−5 builder/src/Elm/Diff.hs+6−6 builder/src/Elm/Install.hs+3−3 builder/src/Elm/Project/Json.hs+3−3 builder/src/Elm/Project/Root.hs+2−3 builder/src/Elm/Publish.hs+9−9 builder/src/File/Args.hs+2−2 builder/src/File/Crawl.hs+5−5 builder/src/File/Find.hs+1−1 builder/src/File/Header.hs+9−9 builder/src/File/IO.hs+3−3 builder/src/Reporting/Error2.hs → builder/src/Reporting/Exit.hs+38−30 builder/src/Reporting/Error/Assets.hs → builder/src/Reporting/Exit/Assets.hs+8−9 builder/src/Reporting/Error/Bump.hs → builder/src/Reporting/Exit/Bump.hs+8−9 builder/src/Reporting/Error/Compile.hs → builder/src/Reporting/Exit/Compile.hs+15−15 builder/src/Reporting/Error/Crawl.hs → builder/src/Reporting/Exit/Crawl.hs+8−9 builder/src/Reporting/Error/Deps.hs → builder/src/Reporting/Exit/Deps.hs+8−9 builder/src/Reporting/Error/Diff.hs → builder/src/Reporting/Exit/Diff.hs+8−9 builder/src/Reporting/Error/Help.hs → builder/src/Reporting/Exit/Help.hs+43−14 builder/src/Reporting/Error/Http.hs → builder/src/Reporting/Exit/Http.hs+8−9 builder/src/Reporting/Error/Publish.hs → builder/src/Reporting/Exit/Publish.hs+8−9 builder/src/Reporting/Progress.hs+3−3 builder/src/Reporting/Progress/Repl.hs+5−6 builder/src/Reporting/Progress/Terminal.hs+4−5 builder/src/Reporting/Task.hs+3−4 builder/src/Reporting/Task/Http.hs+9−10
builder/src/Deps/Explorer.hs+3−3
@@ -28,8 +28,8 @@ import Elm.Package (Name, Version)
2828import qualified Deps.Get as Get
2929import qualified Elm.Project.Json as Project
3030import Elm.Project.Constraint (Constraint)
31−import qualified Reporting.Error2 as Error
32−import qualified Reporting.Error.Deps as E
31+import qualified Reporting.Exit as Exit
32+import qualified Reporting.Exit.Deps as E
3333import qualified Reporting.Task as Task
3434
3535
@@ -73,7 +73,7 @@ getVersions name =
7373 return versions
7474
7575 Left _suggestions ->
76− throwError (Error.Deps (E.CorruptVersionCache name))
76+ throwError (Exit.Deps (E.CorruptVersionCache name))
7777
7878
7979
builder/src/Deps/Get.hs+4−4
@@ -28,8 +28,8 @@ import qualified Deps.Website as Website
2828import qualified Elm.Project.Json as Project
2929import qualified Elm.Utils as Utils
3030import qualified File.IO as IO
31−import qualified Reporting.Error2 as Error
32−import qualified Reporting.Error.Assets as E
31+import qualified Reporting.Exit as Exit
32+import qualified Reporting.Exit.Assets as E
3333import qualified Reporting.Progress as Progress
3434import qualified Reporting.Task as Task
3535import qualified Json.Decode as Decode
@@ -129,7 +129,7 @@ info name version =
129129
130130 Left _ ->
131131 do IO.remove elmJson
132− Task.throw $ Error.Assets $ E.CorruptElmJson name version
132+ Task.throw $ Exit.Assets $ E.CorruptElmJson name version
133133
134134
135135
@@ -157,7 +157,7 @@ docs name version =
157157
158158 Left _ ->
159159 do IO.remove docsJson
160− Task.throw $ Error.Assets $ E.CorruptDocumentation name version
160+ Task.throw $ Exit.Assets $ E.CorruptDocumentation name version
161161
162162
163163errorToDocs :: Docs.Error -> [P.Doc]
builder/src/Deps/Verify.hs+5−5
@@ -36,8 +36,8 @@ import qualified File.Compile as Compile
3636import qualified File.Crawl as Crawl
3737import qualified File.IO as IO
3838import qualified File.Plan as Plan
39−import qualified Reporting.Error2 as Error
40−import qualified Reporting.Error.Deps as E
39+import qualified Reporting.Exit as Exit
40+import qualified Reporting.Exit.Deps as E
4141import qualified Reporting.Progress as Progress
4242import qualified Reporting.Task as Task
4343import qualified Stuff.Paths as Paths
@@ -55,9 +55,9 @@ verify root project =
5555 return (solution, summary)
5656
5757
58−throw :: E.Error -> Task.Task a
59−throw err =
60− Task.throw (Error.Deps err)
58+throw :: E.Exit -> Task.Task a
59+throw exit =
60+ Task.throw (Exit.Deps exit)
6161
6262
6363
builder/src/Deps/Website.hs+4−4
@@ -35,7 +35,7 @@ import Elm.Package (Name, Version)
3535import qualified Elm.Package as Pkg
3636import qualified Json.Decode as D
3737
38−import qualified Reporting.Error.Http as E
38+import qualified Reporting.Exit.Http as E
3939import qualified Reporting.Progress as Progress
4040import qualified Reporting.Task as Task
4141import qualified Reporting.Task.Http as Http
@@ -188,7 +188,7 @@ endpointDecoder =
188188-- DOWNLOAD ZIP ARCHIVE
189189
190190
191−downloadArchive :: FilePath -> Name -> Version -> String -> Client.Response Client.BodyReader -> IO (Either E.Error ())
191+downloadArchive :: FilePath -> Name -> Version -> String -> Client.Response Client.BodyReader -> IO (Either E.Exit ())
192192downloadArchive cache name version expectedHash response =
193193 do result <- readArchive (Client.responseBody response) initialArchiveState
194194 case result of
@@ -222,7 +222,7 @@ initialArchiveState =
222222type Sha = SHA.Digest SHA.SHA1State
223223
224224
225−readArchive :: Client.BodyReader -> ArchiveState -> IO (Either E.Error (Sha, Zip.Archive))
225+readArchive :: Client.BodyReader -> ArchiveState -> IO (Either E.Exit (Sha, Zip.Archive))
226226readArchive body (AS len sha zip) =
227227 case zip of
228228 Binary.Fail _ _ _ ->
@@ -303,7 +303,7 @@ githubDownload name version dir =
303303 Client.withResponse request manager (githubDownloadHelp dir)
304304
305305
306−githubDownloadHelp :: FilePath -> Client.Response Client.BodyReader -> IO (Either E.Error Sha)
306+githubDownloadHelp :: FilePath -> Client.Response Client.BodyReader -> IO (Either E.Exit Sha)
307307githubDownloadHelp targetDir response =
308308 do result <- readArchive (Client.responseBody response) initialArchiveState
309309 case result of
builder/src/Elm/Bump.hs+5−5
@@ -17,9 +17,9 @@ import qualified Elm.Package as Pkg
1717import qualified Elm.Project as Project
1818import qualified Elm.Project.Json as Project
1919import qualified Elm.Project.Summary as Summary
20−import qualified Reporting.Error2 as Error
21−import qualified Reporting.Error.Bump as E
22−import qualified Reporting.Error.Help as Help
20+import qualified Reporting.Exit as Exit
21+import qualified Reporting.Exit.Bump as E
22+import qualified Reporting.Exit.Help as Help
2323import qualified Reporting.Progress.Terminal as Terminal
2424import qualified Reporting.Task as Task
2525
@@ -32,7 +32,7 @@ bump :: Summary.Summary -> Task.Task ()
3232bump summary@(Summary.Summary root project _ _ _) =
3333 case project of
3434 Project.App _ ->
35− Task.throw (Error.Bump E.Application)
35+ Task.throw (Exit.Bump E.Application)
3636
3737 Project.Pkg info@(Project.PkgInfo name _ _ version _ _ _ _) ->
3838 do pkgs <- Get.all Get.RequireLatest
@@ -48,7 +48,7 @@ bump summary@(Summary.Summary root project _ _ _) =
4848 if elem version bumpableVersions then
4949 suggestVersion summary info
5050 else
51− Task.throw $ Error.Bump $ E.Unbumpable version $
51+ Task.throw $ Exit.Bump $ E.Unbumpable version $
5252 map head (List.group (List.sort bumpableVersions))
5353
5454
builder/src/Elm/Diff.hs+6−6
@@ -25,9 +25,9 @@ import qualified Elm.Package as Pkg
2525import qualified Elm.Project as Project
2626import qualified Elm.Project.Json as Project
2727import qualified Elm.Project.Summary as Summary
28−import qualified Reporting.Error2 as Error
29−import qualified Reporting.Error.Diff as E
30−import qualified Reporting.Error.Help as Help
28+import qualified Reporting.Exit as Exit
29+import qualified Reporting.Exit.Diff as E
30+import qualified Reporting.Exit.Help as Help
3131import qualified Reporting.Task as Task
3232
3333
@@ -75,9 +75,9 @@ diff args =
7575 writeDoc (toDoc (Diff.diff oldDocs newDocs))
7676
7777
78−throw :: E.Error -> Task.Task a
79−throw err =
80− Task.throw $ Error.Diff err
78+throw :: E.Exit -> Task.Task a
79+throw exit =
80+ Task.throw $ Exit.Diff exit
8181
8282
8383
builder/src/Elm/Install.hs+3−3
@@ -24,7 +24,7 @@ import Elm.Project.Constraint (Constraint)
2424import qualified Elm.Project.Constraint as Con
2525import qualified Elm.Project.Json as Project
2626import qualified Elm.Project.Root as Root
27−import qualified Reporting.Error2 as Error
27+import qualified Reporting.Exit as Exit
2828import qualified Reporting.Task as Task
2929
3030
@@ -146,7 +146,7 @@ addToApp pkg info@(Project.AppInfo _ _ deps tests trans) =
146146
147147 Nothing ->
148148 do badNames <- filterM isBadElm (pkg : Map.keys old)
149− lift $ Task.throw (Error.NoSolution badNames)
149+ lift $ Task.throw (Exit.NoSolution badNames)
150150
151151
152152addToAppHelp :: Name -> Project.AppInfo -> Solver.Solver (Map Name Version)
@@ -186,7 +186,7 @@ addToPkg pkg info@(Project.PkgInfo _ _ _ _ _ deps tests _) =
186186 Nothing ->
187187 do let pkgs = Map.keys deps ++ Map.keys tests
188188 badNames <- filterM isBadElm (pkg : pkgs)
189− lift $ Task.throw (Error.NoSolution badNames)
189+ lift $ Task.throw (Exit.NoSolution badNames)
190190
191191
192192addToPkgHelp :: Name -> Project.PkgInfo -> Solver.Solver (Map Name Constraint)
builder/src/Elm/Project/Json.hs+3−3
@@ -41,8 +41,8 @@ import qualified Elm.Project.Constraint as Con
4141import qualified Elm.Project.Licenses as Licenses
4242import qualified Json.Decode as D
4343import qualified Json.Encode as E
44−import qualified Reporting.Error2 as Error
45−import qualified Reporting.Error.Assets as E
44+import qualified Reporting.Exit as Exit
45+import qualified Reporting.Exit.Assets as E
4646import qualified Reporting.Task as Task
4747
4848
@@ -268,7 +268,7 @@ read path =
268268
269269throwBadJson :: E.ElmJsonProblem -> Task.Task a
270270throwBadJson problem =
271− Task.throw (Error.Assets (E.BadElmJson problem))
271+ Task.throw (Exit.Assets (E.BadElmJson problem))
272272
273273
274274checkOverlap :: String -> String -> Map Name a -> Map Name a -> Task.Task ()
builder/src/Elm/Project/Root.hs+2−3
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
32module Elm.Project.Root
43 ( get
@@ -20,7 +19,7 @@ import Elm.Project.Json (Project(..), PkgInfo(..))
2019import Elm.Project.Summary (Summary)
2120import qualified Elm.PerUserCache as PerUserCache
2221import qualified File.IO as IO
23−import qualified Reporting.Error2 as Error
22+import qualified Reporting.Exit as Exit
2423import qualified Reporting.Task as Task
2524import qualified Stuff.Verify as Verify
2625import qualified Json.Encode as Encode
@@ -55,7 +54,7 @@ moveToRoot =
5554 return root
5655
5756 Nothing ->
58− Task.throw Error.NoElmJson
57+ Task.throw Exit.NoElmJson
5958
6059
6160
builder/src/Elm/Publish.hs+9−9
@@ -22,8 +22,8 @@ import qualified Elm.Package as Pkg
2222import qualified Elm.Project as Project
2323import qualified Elm.Project.Json as Project
2424import qualified Elm.Project.Summary as Summary
25−import qualified Reporting.Error2 as Error
26−import qualified Reporting.Error.Publish as E
25+import qualified Reporting.Exit as Exit
26+import qualified Reporting.Exit.Publish as E
2727import qualified Reporting.Progress as Progress
2828import qualified Reporting.Task as Task
2929import qualified Stuff.Paths as Path
@@ -62,9 +62,9 @@ publish summary@(Summary.Summary root project _ _ _) =
6262 Task.report Progress.PublishEnd
6363
6464
65−throw :: E.Error -> Task.Task a
66−throw err =
67− Task.throw (Error.Publish err)
65+throw :: E.Exit -> Task.Task a
66+throw exit =
67+ Task.throw (Exit.Publish exit)
6868
6969
7070
@@ -191,9 +191,9 @@ phase :: Progress.PublishPhase -> Task.Task a -> Task.Task a
191191phase publishPhase task =
192192 do Task.report $ Progress.PublishProgress publishPhase Nothing
193193
194− result <- task `catchError` \err ->
194+ result <- task `catchError` \exit ->
195195 do Task.report $ Progress.PublishProgress publishPhase (Just Progress.Bad)
196− Task.throw err
196+ Task.throw exit
197197
198198 Task.report $ Progress.PublishProgress publishPhase (Just Progress.Good)
199199
@@ -225,9 +225,9 @@ verifyVersion name version docs maybePublishedVersions =
225225 do (old, magnitude) <- verifyBump name version docs publishedVersions
226226 reportBumpPhase (Progress.GoodBump old magnitude)
227227
228− `catchError` \err ->
228+ `catchError` \exit ->
229229 do reportBumpPhase Progress.BadBump
230− Task.throw err
230+ Task.throw exit
231231
232232
233233verifyBump :: Pkg.Name -> Pkg.Version -> Docs.Documentation -> [Pkg.Version] -> Task.Task (Pkg.Version, Diff.Magnitude)
builder/src/File/Args.hs+2−2
@@ -11,7 +11,7 @@ import Data.List.NonEmpty (NonEmpty((:|)))
1111import qualified Elm.Compiler.Module as Module
1212import qualified Elm.Project.Json as Project
1313import qualified Elm.Project.Summary as Summary
14−import qualified Reporting.Error2 as Error
14+import qualified Reporting.Exit as Exit
1515import qualified Reporting.Task as Task
1616
1717
@@ -37,4 +37,4 @@ fromSummary (Summary.Summary _ project _ _ _) =
3737 return $ Pkg (Project.getExposed info)
3838
3939 Project.App _ ->
40− Task.throw Error.CannotMakeNothing
40+ Task.throw Exit.CannotMakeNothing
builder/src/File/Crawl.hs+5−5
@@ -29,8 +29,8 @@ import qualified File.Args as Args
2929import qualified File.Find as Find
3030import qualified File.Header as Header
3131import qualified File.IO as IO
32−import qualified Reporting.Error2 as Error
33−import qualified Reporting.Error.Crawl as E
32+import qualified Reporting.Exit as Exit
33+import qualified Reporting.Exit.Crawl as E
3434import qualified Reporting.Task as Task
3535
3636
@@ -121,7 +121,7 @@ depthFirstSearch summary unvisited startGraph =
121121 return $ Graph args locals kernels foreigns ()
122122
123123 problem : otherProblems ->
124− Task.throw (Error.Crawl (E.DependencyProblems problem otherProblems))
124+ Task.throw (Exit.Crawl (E.DependencyProblems problem otherProblems))
125125
126126
127127
@@ -147,7 +147,7 @@ checkComponent scc =
147147 return ()
148148
149149 Graph.CyclicSCC names ->
150− Task.throw (Error.Cycle names)
150+ Task.throw (Exit.Cycle names)
151151
152152
153153
@@ -270,7 +270,7 @@ readKContent importDict path =
270270 return content
271271
272272 Left _ ->
273− Task.throw (Error.Crawl (E.BadKernelHeader path))
273+ Task.throw (Exit.Crawl (E.BadKernelHeader path))
274274
275275
276276
builder/src/File/Find.hs+1−1
@@ -18,7 +18,7 @@ import qualified Elm.Package as Pkg
1818
1919import qualified Elm.Project.Json as Project
2020import qualified Elm.Project.Summary as Summary
21−import qualified Reporting.Error.Crawl as E
21+import qualified Reporting.Exit.Crawl as E
2222import qualified Reporting.Task as Task
2323
2424
builder/src/File/Header.hs+9−9
@@ -25,8 +25,8 @@ import qualified Elm.Project.Json as Project
2525import Elm.Project.Json (Project)
2626import Elm.Project.Summary (Summary(..))
2727import qualified File.IO as IO
28−import qualified Reporting.Error2 as Error
29−import qualified Reporting.Error.Crawl as E
28+import qualified Reporting.Exit as Exit
29+import qualified Reporting.Exit.Crawl as E
3030import qualified Reporting.Task as Task
3131
3232
@@ -43,7 +43,7 @@ data Info =
4343 }
4444
4545
46−atRoot :: Task.Task_ E.Problem a -> Task.Task_ E.Error a
46+atRoot :: Task.Task_ E.Problem a -> Task.Task_ E.Exit a
4747atRoot task =
4848 Task.mapError (\problem -> E.DependencyProblems problem []) task
4949
@@ -78,12 +78,12 @@ checkName path expectedName maybeName =
7878
7979readOneFile :: Summary -> FilePath -> Task.Task (Maybe Module.Raw, Info)
8080readOneFile summary path =
81− Task.mapError Error.Crawl $
81+ Task.mapError Exit.Crawl $
8282 do (time, source) <- readOneHelp path
8383 atRoot $ parse (_project summary) path time source
8484
8585
86−readOneHelp :: FilePath -> Task.Task_ E.Error (Time.UTCTime, BS.ByteString)
86+readOneHelp :: FilePath -> Task.Task_ E.Exit (Time.UTCTime, BS.ByteString)
8787readOneHelp path =
8888 do exists <- IO.exists path
8989 if exists
@@ -97,7 +97,7 @@ readOneHelp path =
9797
9898readManyFiles :: Summary -> NonEmpty FilePath -> Task.Task (NonEmpty (Module.Raw, Info))
9999readManyFiles summary files =
100− Task.mapError Error.Crawl $
100+ Task.mapError Exit.Crawl $
101101 do infos <- traverse (readManyFilesHelp summary) files
102102 let insert (name, info) dict = Map.insertWith (<>) name (info :| []) dict
103103 let nameTable = foldr insert Map.empty infos
@@ -105,7 +105,7 @@ readManyFiles summary files =
105105 return infos
106106
107107
108−readManyFilesHelp :: Summary -> FilePath -> Task.Task_ E.Error (Module.Raw, Info)
108+readManyFilesHelp :: Summary -> FilePath -> Task.Task_ E.Exit (Module.Raw, Info)
109109readManyFilesHelp summary path =
110110 do (time, source) <- readOneHelp path
111111 (maybeName, info) <- atRoot $ parse (_project summary) path time source
@@ -117,7 +117,7 @@ readManyFilesHelp summary path =
117117 return (name, info)
118118
119119
120−detectDuplicateNames :: Module.Raw -> NonEmpty Info -> Task.Task_ E.Error ()
120+detectDuplicateNames :: Module.Raw -> NonEmpty Info -> Task.Task_ E.Exit ()
121121detectDuplicateNames name (info :| otherInfos) =
122122 case otherInfos of
123123 [] ->
@@ -134,7 +134,7 @@ detectDuplicateNames name (info :| otherInfos) =
134134
135135readSource :: Project -> BS.ByteString -> Task.Task (Maybe Module.Raw, Info)
136136readSource project source =
137− Task.mapError Error.Crawl $
137+ Task.mapError Exit.Crawl $
138138 atRoot $ parse project "elm" fakeTime source
139139
140140
builder/src/File/IO.hs+3−3
@@ -30,8 +30,8 @@ import qualified System.FilePath as FP
3030import qualified System.IO as IO
3131import System.IO.Error (ioeGetErrorType, annotateIOError, modifyIOError)
3232
33−import qualified Reporting.Error2 as Error
34−import qualified Reporting.Error.Assets as E
33+import qualified Reporting.Exit as Exit
34+import qualified Reporting.Exit.Assets as E
3535import qualified Reporting.Task as Task
3636
3737
@@ -64,7 +64,7 @@ readBinary path =
6464
6565throwCorruptBinary :: FilePath -> Task.Task a
6666throwCorruptBinary filePath =
67− Task.throw (Error.Assets (E.CorruptBinary filePath))
67+ Task.throw (Exit.Assets (E.CorruptBinary filePath))
6868
6969
7070
builder/src/Reporting/Error2.hs → builder/src/Reporting/Exit.hsrenamed+38−30
@@ -1,45 +1,48 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error2
4− ( Error(..)
2+module Reporting.Exit
3+ ( Exit(..)
54 , toString
65 , toStderr
6+ , toJson
77 )
88 where
99
1010
11+import qualified Data.ByteString.Builder as B
12+import System.IO (stderr)
1113import qualified Text.PrettyPrint.ANSI.Leijen as P
1214
1315import qualified Elm.Compiler as Compiler
1416import qualified Elm.Compiler.Module as Module
1517import qualified Elm.Package as Pkg
1618import qualified Elm.Utils as Utils
17−import qualified Reporting.Error.Assets as Asset
18−import qualified Reporting.Error.Bump as Bump
19−import qualified Reporting.Error.Compile as Compile
20−import qualified Reporting.Error.Crawl as Crawl
21−import qualified Reporting.Error.Deps as Deps
22−import qualified Reporting.Error.Diff as Diff
23−import qualified Reporting.Error.Help as Help
24−import qualified Reporting.Error.Http as Http
25−import qualified Reporting.Error.Publish as Publish
19+import qualified Json.Encode as Encode
20+import qualified Reporting.Exit.Assets as Asset
21+import qualified Reporting.Exit.Bump as Bump
22+import qualified Reporting.Exit.Compile as Compile
23+import qualified Reporting.Exit.Crawl as Crawl
24+import qualified Reporting.Exit.Deps as Deps
25+import qualified Reporting.Exit.Diff as Diff
26+import qualified Reporting.Exit.Help as Help
27+import qualified Reporting.Exit.Http as Http
28+import qualified Reporting.Exit.Publish as Publish
2629
2730
2831
2932-- ALL POSSIBLE ERRORS
3033
3134
32−data Error
35+data Exit
3336 = NoElmJson
34− | Assets Asset.Error
35− | Bump Bump.Error
36− | Compile Compile.Error [Compile.Error]
37− | Crawl Crawl.Error
37+ | Assets Asset.Exit
38+ | Bump Bump.Exit
39+ | Compile Compile.Exit [Compile.Exit]
40+ | Crawl Crawl.Exit
3841 | Cycle [Module.Raw] -- TODO write docs to help with this scenario
39− | Deps Deps.Error
40− | Diff Diff.Error
41− | Publish Publish.Error
42− | BadHttp String Http.Error
42+ | Deps Deps.Exit
43+ | Diff Diff.Exit
44+ | Publish Publish.Exit
45+ | BadHttp String Http.Exit
4346
4447 -- install
4548 | NoSolution [Pkg.Name]
@@ -50,19 +53,24 @@ data Error
5053-- RENDERERS
5154
5255
53−toString :: Error -> String
54−toString err =
55− Help.toString (Help.reportToDoc (toReport err))
56+toString :: Exit -> String
57+toString exit =
58+ Help.toString (Help.reportToDoc (toReport exit))
5659
5760
58−toStderr :: Error -> IO ()
59−toStderr err =
60− Help.toStderr (Help.reportToDoc (toReport err))
61+toStderr :: Exit -> IO ()
62+toStderr exit =
63+ Help.toStderr (Help.reportToDoc (toReport exit))
6164
6265
63−toReport :: Error -> Help.Report
64−toReport err =
65− case err of
66+toJson :: Exit -> IO ()
67+toJson exit =
68+ B.hPutBuilder stderr $ Encode.encodeUgly $ Help.reportToJson (toReport exit)
69+
70+
71+toReport :: Exit -> Help.Report
72+toReport exit =
73+ case exit of
6674 NoElmJson ->
6775 Help.report "WELCOME" Nothing
6876 "It looks like you are trying to start a new Elm project. Very exciting! :D"
builder/src/Reporting/Error/Assets.hs → builder/src/Reporting/Exit/Assets.hsrenamed+8−9
@@ -1,7 +1,6 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Assets
4− ( Error(..)
2+module Reporting.Exit.Assets
3+ ( Exit(..)
54 , ElmJsonProblem(..)
65 , toReport
76 , BadElmJsonContent(..)
@@ -15,14 +14,14 @@ import qualified Data.Text as Text
1514import qualified Text.PrettyPrint.ANSI.Leijen as P
1615
1716import qualified Elm.Package as Pkg
18−import qualified Reporting.Error.Help as Help
17+import qualified Reporting.Exit.Help as Help
1918
2019
2120
22−-- ERRORS
21+-- EXITS
2322
2423
25−data Error
24+data Exit
2625 = BadElmJson ElmJsonProblem
2726 | CorruptElmJson Pkg.Name Pkg.Version
2827 | CorruptDocumentation Pkg.Name Pkg.Version
@@ -43,9 +42,9 @@ data ElmJsonProblem
4342-- TO REPORT
4443
4544
46−toReport :: Error -> Help.Report
47−toReport err =
48− case err of
45+toReport :: Exit -> Help.Report
46+toReport exit =
47+ case exit of
4948 CorruptElmJson pkg vsn ->
5049 corruptJsonToReport "elm.json" pkg vsn
5150
builder/src/Reporting/Error/Bump.hs → builder/src/Reporting/Exit/Bump.hsrenamed+8−9
@@ -1,7 +1,6 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Bump
4− ( Error(..)
2+module Reporting.Exit.Bump
3+ ( Exit(..)
54 , toReport
65 )
76 where
@@ -11,14 +10,14 @@ import Data.Monoid ((<>))
1110import qualified Text.PrettyPrint.ANSI.Leijen as P
1211
1312import qualified Elm.Package as Pkg
14−import qualified Reporting.Error.Help as Help
13+import qualified Reporting.Exit.Help as Help
1514
1615
1716
18−-- ERRORS
17+-- EXITS
1918
2019
21−data Error
20+data Exit
2221 = Application
2322 | Unbumpable Pkg.Version [Pkg.Version]
2423
@@ -27,9 +26,9 @@ data Error
2726-- TO REPORT
2827
2928
30−toReport :: Error -> Help.Report
31−toReport err =
32− case err of
29+toReport :: Exit -> Help.Report
30+toReport exit =
31+ case exit of
3332 Application ->
3433 Help.report "UNBUMPABLE" (Just "elm.json")
3534 "Your elm.json says this is an application. That means it cannot be published\
builder/src/Reporting/Error/Compile.hs → builder/src/Reporting/Exit/Compile.hsrenamed+15−15
@@ -1,7 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Compile
4− ( Error(..)
3+module Reporting.Exit.Compile
4+ ( Exit(..)
55 , toDoc
66 )
77 where
@@ -18,11 +18,11 @@ import qualified Elm.Compiler.Module as Module
1818
1919
2020
21−-- ERRORS
21+-- EXITS
2222
2323
24−data Error =
25− Error
24+data Exit =
25+ Exit
2626 { _name :: Module.Raw
2727 , _path :: FilePath
2828 , _time :: Time.UTCTime
@@ -35,25 +35,25 @@ data Error =
3535-- TO DOC
3636
3737
38−toDoc :: Error -> [Error] -> P.Doc
38+toDoc :: Exit -> [Exit] -> P.Doc
3939toDoc e es =
4040 case NonEmpty.sortWith _time (e :| es) of
41− err :| errors ->
42− P.vcat (toDocHelp err errors)
41+ exit :| exits ->
42+ P.vcat (toDocHelp exit exits)
4343
4444
45−toDocHelp :: Error -> [Error] -> [P.Doc]
46−toDocHelp e1 errs =
47− case errs of
45+toDocHelp :: Exit -> [Exit] -> [P.Doc]
46+toDocHelp e1 exits =
47+ case exits of
4848 [] ->
49− [errorToDoc e1]
49+ [exitToDoc e1]
5050
5151 e2 : otherErrors ->
52− errorToDoc e1 : separator (_name e1) (_name e2) : toDocHelp e2 otherErrors
52+ exitToDoc e1 : separator (_name e1) (_name e2) : toDocHelp e2 otherErrors
5353
5454
55−errorToDoc :: Error -> P.Doc
56−errorToDoc (Error _name path _time source errors) =
55+exitToDoc :: Exit -> P.Doc
56+exitToDoc (Exit _name path _time source errors) =
5757 Compiler.errorsToDoc path source errors
5858
5959
builder/src/Reporting/Error/Crawl.hs → builder/src/Reporting/Exit/Crawl.hsrenamed+8−9
@@ -1,7 +1,6 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Crawl
4− ( Error(..)
2+module Reporting.Exit.Crawl
3+ ( Exit(..)
54 , Problem(..)
65 , Origin(..)
76 , toReport
@@ -19,14 +18,14 @@ import Text.PrettyPrint.ANSI.Leijen ((<+>), (<>))
1918import qualified Elm.Compiler as Compiler
2019import qualified Elm.Compiler.Module as Module
2120import qualified Elm.Package as Pkg
22−import qualified Reporting.Error.Help as Help
21+import qualified Reporting.Exit.Help as Help
2322
2423
2524
26−-- ERROR
25+-- EXIT
2726
2827
29−data Error
28+data Exit
3029 = RootFileNotFound FilePath
3130 | RootModuleNameDuplicate Module.Raw [FilePath]
3231 | RootNameless FilePath
@@ -58,9 +57,9 @@ data Origin
5857-- TO REPORT
5958
6059
61−toReport :: Error -> Help.Report
62−toReport err =
63− case err of
60+toReport :: Exit -> Help.Report
61+toReport exit =
62+ case exit of
6463 RootFileNotFound path ->
6564 Help.report "FILE NOT FOUND" Nothing
6665 "You want me to compile this file:"
builder/src/Reporting/Error/Deps.hs → builder/src/Reporting/Exit/Deps.hsrenamed+8−9
@@ -1,7 +1,6 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Deps
4− ( Error(..)
2+module Reporting.Exit.Deps
3+ ( Exit(..)
54 , toReport
65 )
76 where
@@ -12,14 +11,14 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
1211import qualified Elm.Compiler as Compiler
1312import qualified Elm.Package as Pkg
1413import qualified Elm.Project.Constraint as Con
15−import qualified Reporting.Error.Help as Help
14+import qualified Reporting.Exit.Help as Help
1615
1716
1817
19−-- ERRORS
18+-- EXITS
2019
2120
22−data Error
21+data Exit
2322 = CorruptVersionCache Pkg.Name
2423 | PackageNotFound Pkg.Name [Pkg.Name]
2524 -- verify
@@ -33,9 +32,9 @@ data Error
3332-- TO DOC
3433
3534
36−toReport :: Error -> Help.Report
37−toReport err =
38− case err of
35+toReport :: Exit -> Help.Report
36+toReport exit =
37+ case exit of
3938 CorruptVersionCache pkg ->
4039 Help.report "CORRUPT CACHE" Nothing
4140 ( "I ran into an unknown package while exploring dependencies:"
builder/src/Reporting/Error/Diff.hs → builder/src/Reporting/Exit/Diff.hsrenamed+8−9
@@ -1,7 +1,6 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Diff
4− ( Error(..)
2+module Reporting.Exit.Diff
3+ ( Exit(..)
54 , toReport
65 )
76 where
@@ -10,14 +9,14 @@ import qualified Data.List as List
109import qualified Text.PrettyPrint.ANSI.Leijen as P
1110
1211import qualified Elm.Package as Pkg
13−import qualified Reporting.Error.Help as Help
12+import qualified Reporting.Exit.Help as Help
1413
1514
1615
17−-- ERRORS
16+-- EXITS
1817
1918
20−data Error
19+data Exit
2120 = Application
2221 | UnknownPackage Pkg.Name [Pkg.Name]
2322 | UnknownVersion Pkg.Name Pkg.Version [Pkg.Version]
@@ -27,9 +26,9 @@ data Error
2726-- TO DOC
2827
2928
30−toReport :: Error -> Help.Report
31−toReport err =
32− case err of
29+toReport :: Exit -> Help.Report
30+toReport exit =
31+ case exit of
3332 Application ->
3433 Help.report "CANNOT DIFF APPLICATIONS" Nothing
3534 "I cannot perform diffs on applications, only packages! If you are\
builder/src/Reporting/Error/Help.hs → builder/src/Reporting/Exit/Help.hsrenamed+43−14
@@ -1,11 +1,11 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Help
2+module Reporting.Exit.Help
43 ( Report
54 , report
65 , docReport
76 , compilerReport
87 , reportToDoc
8+ , reportToJson
99 , hintLink
1010 , stack
1111 , reflow
@@ -16,7 +16,9 @@ module Reporting.Error.Help
1616 )
1717 where
1818
19+
1920import qualified Data.List as List
21+import qualified Data.Text as Text
2022import GHC.IO.Handle (hIsTerminalDevice)
2123import System.IO (Handle, hPutStr, stderr, stdout)
2224import qualified Text.PrettyPrint.ANSI.Leijen as P
@@ -24,6 +26,7 @@ import Text.PrettyPrint.ANSI.Leijen ((<>),(<+>))
2426
2527import qualified Elm.Compiler as Compiler
2628import qualified Elm.Package as Pkg
29+import qualified Json.Encode as Encode
2730
2831
2932
@@ -31,37 +34,40 @@ import qualified Elm.Package as Pkg
3134
3235
3336data Report
34− = FromCompiler P.Doc
37+ = CompileErrors
3538 | Report
3639 { _title :: String
3740 , _path :: Maybe FilePath
38− , _start :: P.Doc
39− , _others :: [P.Doc]
41+ , _message :: P.Doc
4042 }
4143
4244
4345report :: String -> Maybe FilePath -> String -> [P.Doc] -> Report
44−report title maybePath startString others =
45− Report title maybePath (P.text startString) others
46+report title path startString others =
47+ Report title path $ stack (reflow startString:others)
4648
4749
4850docReport :: String -> Maybe FilePath -> P.Doc -> [P.Doc] -> Report
49−docReport =
50− Report
51+docReport title path startDoc others =
52+ Report title path $ stack (startDoc:others)
5153
5254
5355compilerReport :: P.Doc -> Report
5456compilerReport =
55− FromCompiler
57+ error "TODO compilerReport"
58+
59+
60+
61+-- TO DOC
5662
5763
5864reportToDoc :: Report -> P.Doc
5965reportToDoc report_ =
6066 case report_ of
61− FromCompiler doc ->
62− doc
67+ CompileErrors ->
68+ error "TODO reportToDoc"
6369
64− Report title maybePath start others ->
70+ Report title maybePath message ->
6571 let
6672 makeDashes n =
6773 replicate (max 1 (80 - n)) '-'
@@ -78,7 +84,30 @@ reportToDoc report_ =
7884 P.dullcyan $
7985 "--" <+> P.text title <+> P.text errorBarEnd
8086 in
81− stack (errorBar : start : others ++ [""])
87+ stack [errorBar, message, ""]
88+
89+
90+
91+-- TO JSON
92+
93+
94+reportToJson :: Report -> Encode.Value
95+reportToJson report_ =
96+ case report_ of
97+ CompileErrors ->
98+ error "TODO reportToJson"
99+
100+ Report title maybePath message ->
101+ let
102+ messageString =
103+ P.displayS (P.renderPretty 1 80 message) ""
104+ in
105+ Encode.object
106+ [ ("type", Encode.text "error")
107+ , ("path", maybe Encode.null (Encode.text . Text.pack) maybePath)
108+ , ("title", Encode.text (Text.pack title))
109+ , ("message", Encode.text (Text.pack messageString))
110+ ]
82111
83112
84113
builder/src/Reporting/Error/Http.hs → builder/src/Reporting/Exit/Http.hsrenamed+8−9
@@ -1,7 +1,6 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Http
4− ( Error(..)
2+module Reporting.Exit.Http
3+ ( Exit(..)
54 , toReport
65 , BadJson(..)
76 , badJsonToDocs
@@ -13,14 +12,14 @@ import qualified Data.Text as Text
1312import Text.PrettyPrint.ANSI.Leijen ((<>))
1413import qualified Text.PrettyPrint.ANSI.Leijen as P
1514
16−import qualified Reporting.Error.Help as Help
15+import qualified Reporting.Exit.Help as Help
1716
1817
1918
20−-- ERRORS
19+-- EXITS
2120
2221
23−data Error
22+data Exit
2423 = Unknown String
2524 | BadJson P.Doc
2625 | BadZipData
@@ -31,13 +30,13 @@ data Error
3130-- TO REPORT
3231
3332
34−toReport :: String -> Error -> Help.Report
35−toReport url err =
33+toReport :: String -> Exit -> Help.Report
34+toReport url exit =
3635 let
3736 urlDoc =
3837 P.indent 4 $ P.dullyellow $ "<" <> P.text url <> ">"
3938 in
40− case err of
39+ case exit of
4140 Unknown message ->
4241 Help.report "HTTP PROBLEM" Nothing "The following HTTP request failed:"
4342 [ urlDoc
builder/src/Reporting/Error/Publish.hs → builder/src/Reporting/Exit/Publish.hsrenamed+8−9
@@ -1,7 +1,6 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error.Publish
4− ( Error(..)
2+module Reporting.Exit.Publish
3+ ( Exit(..)
54 , toReport
65 )
76 where
@@ -12,14 +11,14 @@ import Text.PrettyPrint.ANSI.Leijen ((<>))
1211
1312import Deps.Diff (Magnitude, magnitudeToString)
1413import qualified Elm.Package as Pkg
15−import qualified Reporting.Error.Help as Help
14+import qualified Reporting.Exit.Help as Help
1615
1716
1817
19−-- ERRORS
18+-- EXITS
2019
2120
22−data Error
21+data Exit
2322 = Application
2423 | NotInitialVersion Pkg.Version
2524 | AlreadyPublished Pkg.Version
@@ -39,9 +38,9 @@ data Error
3938-- TO REPORT
4039
4140
42−toReport :: Error -> Help.Report
43−toReport err =
44− case err of
41+toReport :: Exit -> Help.Report
42+toReport exit =
43+ case exit of
4544 Application ->
4645 Help.report "UNPUBLISHABLE" Nothing "I cannot publish applications, only packages!" []
4746
builder/src/Reporting/Progress.hs+3−3
@@ -16,7 +16,7 @@ import Control.Concurrent.MVar (MVar, readMVar)
1616import qualified Elm.Compiler.Module as Module
1717import Deps.Diff (Magnitude)
1818import Elm.Package (Name, Version)
19−import Reporting.Error2 (Error)
19+import Reporting.Exit (Exit)
2020
2121
2222
@@ -26,7 +26,7 @@ import Reporting.Error2 (Error)
2626data Reporter =
2727 Reporter
2828 { _tell :: Progress -> IO ()
29− , _end :: Maybe Error -> IO ()
29+ , _end :: Maybe Exit -> IO ()
3030 }
3131
3232
@@ -47,7 +47,7 @@ makeReporter chan mvar =
4747-- MESSAGES
4848
4949
50−data Msg = Progress Progress | End (Maybe Error)
50+data Msg = Progress Progress | End (Maybe Exit)
5151
5252
5353data Progress
builder/src/Reporting/Progress/Repl.hs+5−6
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21module Reporting.Progress.Repl
32 ( create
43 )
@@ -9,7 +8,7 @@ import Control.Concurrent (forkIO)
98import Control.Concurrent.Chan (Chan, newChan, readChan)
109import Control.Concurrent.MVar (newEmptyMVar, putMVar)
1110
12−import qualified Reporting.Error2 as Error
11+import qualified Reporting.Exit as Exit
1312import qualified Reporting.Progress as Progress
1413
1514
@@ -36,10 +35,10 @@ loop chan =
3635 Progress.Progress _ ->
3736 loop chan
3837
39− Progress.End maybeError ->
40− case maybeError of
41− Just err ->
42− Error.toStderr err
38+ Progress.End maybeExit ->
39+ case maybeExit of
40+ Just exit ->
41+ Exit.toStderr exit
4342
4443 Nothing ->
4544 return ()
builder/src/Reporting/Progress/Terminal.hs+4−5
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21module Reporting.Progress.Terminal
32 ( create
43 , newPackageOverview
@@ -17,8 +16,8 @@ import qualified Elm.Package as Pkg
1716import Elm.Package (Name, Version)
1817
1918import qualified Deps.Diff as Diff
20−import qualified Reporting.Error2 as Error
21−import qualified Reporting.Error.Help as Help
19+import qualified Reporting.Exit as Exit
20+import qualified Reporting.Exit.Help as Help
2221import Reporting.Progress (Msg(..), Progress(..), Outcome(..), PublishPhase(..), BumpPhase(..))
2322import qualified Reporting.Progress as Progress
2423import qualified Reporting.Progress.Bar as Bar
@@ -56,8 +55,8 @@ loop :: Chan Msg -> State -> IO ()
5655loop chan state =
5756 do msg <- readChan chan
5857 case msg of
59− End (Just err) ->
60− Error.toStderr err
58+ End (Just exit) ->
59+ Exit.toStderr exit
6160
6261 End Nothing ->
6362 return ()
builder/src/Reporting/Task.hs+3−4
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
32module Reporting.Task
43 ( Task, Task_, run, throw, mapError
@@ -31,7 +30,7 @@ import qualified System.IO as IO
3130import Elm.Package (Name, Version)
3231import qualified Elm.Package as Pkg
3332import qualified Elm.PerUserCache as PerUserCache
34−import qualified Reporting.Error2 as Error
33+import qualified Reporting.Exit as Exit
3534import qualified Reporting.Progress as Progress
3635
3736
@@ -40,7 +39,7 @@ import qualified Reporting.Progress as Progress
4039
4140
4241type Task =
43− Task_ Error.Error
42+ Task_ Exit.Exit
4443
4544
4645type Task_ e =
@@ -184,7 +183,7 @@ initPool size =
184183-- HTTP
185184
186185
187−runHttp :: (Http.Manager -> (Progress.Progress -> IO ()) -> IO (Either Error.Error a)) -> Task a
186+runHttp :: (Http.Manager -> (Progress.Progress -> IO ()) -> IO (Either Exit.Exit a)) -> Task a
188187runHttp fetcher =
189188 do (Env _ _ manager tell) <- ask
190189 result <- liftIO $ fetcher manager tell
builder/src/Reporting/Task/Http.hs+9−10
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE GADTs #-}
32{-# LANGUAGE OverloadedStrings #-}
43module Reporting.Task.Http
@@ -24,8 +23,8 @@ import qualified Network.HTTP.Client as Http
2423
2524import qualified Elm.Compiler as Compiler
2625import qualified Elm.Package as Pkg
27−import qualified Reporting.Error2 as Error
28−import qualified Reporting.Error.Http as E
26+import qualified Reporting.Exit as Exit
27+import qualified Reporting.Exit.Http as E
2928import qualified Reporting.Progress as Progress
3029import qualified Reporting.Task as Task
3130
@@ -43,7 +42,7 @@ data Fetch a where
4342
4443
4544type Handler a =
46− Http.Request -> Http.Manager -> IO (Either E.Error a)
45+ Http.Request -> Http.Manager -> IO (Either E.Exit a)
4746
4847
4948package :: String -> [(String,String)] -> Handler a -> Fetch a
@@ -83,7 +82,7 @@ run fetch =
8382 readMVar =<< runHelp chan manager tell fetch
8483
8584
86−runHelp :: Chan (IO ()) -> Http.Manager -> (Progress.Progress -> IO ()) -> Fetch a -> IO (MVar (Either Error.Error a))
85+runHelp :: Chan (IO ()) -> Http.Manager -> (Progress.Progress -> IO ()) -> Fetch a -> IO (MVar (Either Exit.Exit a))
8786runHelp chan manager tell fetch =
8887 case fetch of
8988 Package path params handler ->
@@ -162,13 +161,13 @@ versionParam =
162161-- HTTP HELP
163162
164163
165−fetchSafe :: String -> Http.Manager -> Handler a -> IO (Either Error.Error a)
164+fetchSafe :: String -> Http.Manager -> Handler a -> IO (Either Exit.Exit a)
166165fetchSafe url manager handler =
167166 fetchUnsafe url manager handler
168167 `catch` \e -> handleAnyError url (e :: SomeException)
169168
170169
171−fetchUnsafe :: String -> Http.Manager -> Handler a -> IO (Either Error.Error a)
170+fetchUnsafe :: String -> Http.Manager -> Handler a -> IO (Either Exit.Exit a)
172171fetchUnsafe url manager handler =
173172 do request <- Http.parseUrlThrow url
174173 result <- handler request manager
@@ -177,9 +176,9 @@ fetchUnsafe url manager handler =
177176 return (Right value)
178177
179178 Left problem ->
180− return (Left (Error.BadHttp url problem))
179+ return (Left (Exit.BadHttp url problem))
181180
182181
183−handleAnyError :: (Exception e) => String -> e -> IO (Either Error.Error a)
182+handleAnyError :: (Exception e) => String -> e -> IO (Either Exit.Exit a)
184183handleAnyError url exception =
185− return $ Left $ Error.BadHttp url $ E.Unknown $ show exception
184+ return $ Left $ Exit.BadHttp url $ E.Unknown $ show exception