on 8f7c3cd help sign in
153 lines 5.0 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error
4 ( Error(..)
5 , toString
6 , toStderr
7 )
8 where
11import qualified Text.PrettyPrint.ANSI.Leijen as P
13import qualified Elm.Compiler as Compiler
14import qualified Elm.Compiler.Module as Module
15import qualified Elm.Package as Pkg
16import qualified Elm.Utils as Utils
17import qualified Reporting.Error.Assets as Asset
18import qualified Reporting.Error.Bump as Bump
19import qualified Reporting.Error.Compile as Compile
20import qualified Reporting.Error.Crawl as Crawl
21import qualified Reporting.Error.Deps as Deps
22import qualified Reporting.Error.Diff as Diff
23import qualified Reporting.Error.Help as Help
24import qualified Reporting.Error.Http as Http
25import qualified Reporting.Error.Publish as Publish
29-- ALL POSSIBLE ERRORS
32data Error
33 = NoElmJson
34 | Assets Asset.Error
35 | Bump Bump.Error
36 | Compile Compile.Error [Compile.Error]
37 | Crawl Crawl.Error
38 | 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
44 -- install
45 | NoSolution [Pkg.Name]
46 | CannotMakeNothing
50-- RENDERERS
53toString :: Error -> String
54toString err =
55 Help.toString (Help.reportToDoc (toReport err))
58toStderr :: Error -> IO ()
59toStderr err =
60 Help.toStderr (Help.reportToDoc (toReport err))
63toReport :: Error -> Help.Report
64toReport err =
65 case err of
66 NoElmJson ->
67 Help.report "WELCOME" Nothing
68 "It looks like you are trying to start a new Elm project. Very exciting! :D"
69 [ P.fillSep
70 ["I","very","highly","recommend","working","through"
71 ,P.green "<https://guide.elm-lang.org>","which","will","teach","you","the"
72 ,"basics","of","Elm,","including","how","to","start","new","projects."
73 ]
74 , P.fillSep
75 ["For","folks","who","have","already","built","stuff","with","Elm,","the"
76 ,"problem","is","just","that","there","is","no",P.dullyellow "elm.json","yet."
77 ,"If","you","want","to","work","from","an","example,","check","out","the"
78 ,"one","at","<https://github.com/evancz/elm-todomvc/blob/master/elm.json>"
79 ]
80 , Help.reflow
81 "Whatever your scenario, I hope you have a lovely time using Elm!"
82 ]
84 Assets assetError ->
85 Asset.toReport assetError
87 Bump bumpError ->
88 Bump.toReport bumpError
90 Compile e es ->
91 Help.compilerReport $ Compile.toDoc e es
93 Crawl crawlError ->
94 Crawl.toReport crawlError
96 Cycle names ->
97 Help.report "IMPORT CYCLE" Nothing
98 "Your module imports form a cycle:"
99 [ P.indent 4 (Utils.drawCycle names)
100 , Help.reflow $
101 "Learn more about why this is disallowed and how to break cycles here:"
102 ++ Help.hintLink "import-cycles"
103 ]
105 Deps depsError ->
106 Deps.toReport depsError
108 Diff commandsError ->
109 Diff.toReport commandsError
111 Publish publishError ->
112 Publish.toReport publishError
114 BadHttp url httpError ->
115 Http.toReport url httpError
117 NoSolution badPackages ->
118 case badPackages of
119 [] ->
120 Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json")
121 "This usually happens if you try to modify dependency constraints by\
122 \ hand. I recommend deleting any dependency you added recently (or all\
123 \ of them if things are bad) and then adding them again with:"
124 [ P.indent 4 $ P.green "elm install"
125 , Help.reflow $
126 "And do not be afaid to ask for help on Slack if you get stuck!"
127 ]
129 _:_ ->
130 Help.report "OLD DEPENDENCIES" (Just "elm.json")
131 ( "You are using Elm " ++ Pkg.versionToString Compiler.version
132 ++ ", but the following packages have not been updated for this version yet:"
133 )
134 [ P.vcat $ map (P.red . P.text . Pkg.toString) badPackages
135 , Help.note
136 "Please be kind to the relevant package authors! Having friendly interactions\
137 \ with users is great motivation, and conversely, getting berated by strangers\
138 \ on the internet sucks your soul dry. Furthermore, package authors are humans\
139 \ with families, friends, jobs, vacations, responsibilities, goals, etc. They\
140 \ face obstacles outside of their technical work you will never know about,\
141 \ so please assume the best and try to be patient and supportive!"
142 ]
144 CannotMakeNothing ->
145 Help.report "NO INPUT" Nothing
146 "What should I make though? I need more information, like:"
147 [ P.vcat
148 [ P.indent 4 $ P.green "elm make MyThing.elm"
149 , P.indent 4 $ P.green "elm make This.elm That.elm"
150 ]
151 , Help.reflow
152 "However many files you give, I will create one JS file out of them."
153 ]