@@ -22,9 +22,10 @@ module Reporting.Exit
2222 , OutlineProblem(..)
2323 --
2424 , Details(..)
25− , RegistryProblem(..)
2625 , PackageProblem(..)
2726 --
27+ , RegistryProblem(..)
28+ --
2829 , Make(..)
2930 , BuildProblem(..)
3031 , BuildProjectProblem(..)
@@ -39,8 +40,13 @@ module Reporting.Exit
3940 where
4041
4142
43+import qualified Data.ByteString as BS
44+import qualified Data.ByteString.UTF8 as BS_UTF8
4245import qualified Data.List as List
4346import qualified Data.NonEmptyList as NE
47+import qualified Network.HTTP.Client as HTTP
48+import qualified Network.HTTP.Types.Header as HTTP
49+import qualified Network.HTTP.Types.Status as HTTP
4450
4551import qualified Elm.Constraint as C
4652import qualified Elm.Magnitude as M
@@ -107,8 +113,9 @@ initToReport exit =
107113 ]
108114 ]
109115
110− InitRegistryProblem _ ->
111− error "TODO InitRegistryProblem"
116+ InitRegistryProblem problem ->
117+ toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
118+ "I need the list of published packages before I can start initializing projects"
112119
113120
114121
@@ -119,12 +126,12 @@ data Diff
119126 = DiffNoOutline
120127 | DiffBadOutline Outline
121128 | DiffApplication
122− | DiffNoExposed
129+ | DiffNoExposed Pkg.Name
123130 | DiffUnpublished
124131 | DiffUnknownPackage Pkg.Name [Pkg.Name]
125132 | DiffUnknownVersion Pkg.Name V.Version [V.Version]
126133 | DiffDocsProblem DocsProblem
127− | DiffBadRegistry RegistryProblem
134+ | DiffMustHaveLatestRegistry RegistryProblem
128135 | DiffBadDetails Details
129136 | DiffBadBuild BuildProblem
130137
@@ -137,23 +144,26 @@ diffToReport diff =
137144 "I cannot find an elm.json so I am not sure what you want me to diff.\
138145 \ Normally you run `elm diff` from within a project!"
139146 [ D.reflow $ "If you are just curious to see a diff, try running this command:"
140− , D.indent 4 $ D.green $ "elm diff elm/html 5.1.1 6.0.0"
147+ , D.indent 4 $ D.green $ "elm diff elm/http 1.0.0 2.0.0"
141148 ]
142149
143150 DiffBadOutline outline ->
144151 toOutlineReport outline
145152
146153 DiffApplication ->
147− Help.report "CANNOT DIFF APPLICATIONS" Nothing
148− "It looks like you are running `elm diff` on an application, but it\
149− \ only makes sense for packages that have been published. That way\
150− \ there is a fixed API to diff against."
154+ Help.report "CANNOT DIFF APPLICATIONS" (Just "elm.json")
155+ "Your elm.json says this project is an application, but `elm diff` only works\
156+ \ with packages. That way there are previously published versions of the API to\
157+ \ diff against!"
151158 [ D.reflow $ "If you are just curious to see a diff, try running this command:"
152− , D.indent 4 $ D.green $ "elm diff elm/html 5.1.1 6.0.0"
159+ , D.indent 4 $ D.dullyellow $ "elm diff elm/http 1.0.0 2.0.0"
153160 ]
154161
155− DiffNoExposed ->
156− error "TODO DiffNoExposed"
162+ DiffNoExposed pkg ->
163+ Help.report "NO EXPOSED MODULES" (Just "elm.json")
164+ "Your elm.json has no \"exposed-modules\" which means there is no public API at\
165+ \ all right now! Try adding some modules back to this field."
166+ []
157167
158168 DiffUnpublished ->
159169 Help.report "UNPUBLISHED" Nothing
@@ -191,8 +201,9 @@ diffToReport diff =
191201 DiffDocsProblem problem ->
192202 error "TODO DiffDocsProblem" problem
193203
194− DiffBadRegistry problem ->
195− error "TODO DiffBadRegistry" problem
204+ DiffMustHaveLatestRegistry problem ->
205+ toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
206+ "I need the latest list of published packages before I do this diff"
196207
197208 DiffBadDetails details ->
198209 error "TODO DiffBadDetails" details
@@ -218,7 +229,13 @@ bumpToReport :: Bump -> Help.Report
218229bumpToReport bump =
219230 case bump of
220231 BumpNoOutline ->
221− error "TODO BumpNoOutline"
232+ Help.report "BUMP WHAT?" Nothing
233+ "I cannot find an elm.json so I am not sure what you want me to bump."
234+ [ D.reflow $
235+ "Elm packages always have an elm.json that says current the version number. If\
236+ \ you run this command from a directory with an elm.json file, I will try to bump\
237+ \ the version in there based on the API changes."
238+ ]
222239
223240 BumpBadOutline outline ->
224241 toOutlineReport outline
@@ -246,7 +263,8 @@ bumpToReport bump =
246263 ]
247264
248265 BumpMustHaveLatestRegistry problem ->
249− error "TODO BumpMustHaveLatestRegistry" problem
266+ toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
267+ "I need the latest list of published packages before I can bump any versions"
250268
251269 BumpCannotFindDocs name version problem ->
252270 error "TODO BumpCannotFindDocs" name version problem
@@ -315,7 +333,12 @@ publishToReport :: Publish -> Help.Report
315333publishToReport publish =
316334 case publish of
317335 PublishNoOutline ->
318− error "TODO PublishNoOutline"
336+ Help.report "PUBLISH WHAT?" Nothing
337+ "I cannot find an elm.json so I am not sure what you want me to publish."
338+ [ D.reflow $
339+ "Elm packages always have an elm.json that states the version number,\
340+ \ dependencies, exposed modules, etc."
341+ ]
319342
320343 PublishBadOutline outline ->
321344 toOutlineReport outline
@@ -324,7 +347,8 @@ publishToReport publish =
324347 error "TODO PublishBadDetails" problem
325348
326349 PublishMustHaveLatestRegistry problem ->
327− error "TODO PublishMustHaveLatestRegistry" problem
350+ toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
351+ "I need the latest list of published packages to make sure this is safe to publish"
328352
329353 PublishApplication ->
330354 Help.report "UNPUBLISHABLE" Nothing "I cannot publish applications, only packages!" []
@@ -713,11 +737,6 @@ data Details
713737 | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
714738
715739
716−data RegistryProblem
717− = RP_Http Http.Error
718− | RP_Data
719−
720−
721740data PackageProblem
722741 = PP_BadEndpointRequest Http.Error
723742 | PP_BadEndpointContent
@@ -727,6 +746,119 @@ data PackageProblem
727746
728747
729748
749+-- REGISTRY PROBLEM
750+
751+
752+data RegistryProblem
753+ = RP_Http Http.Error
754+ | RP_Data String BS.ByteString
755+
756+
757+toRegistryProblemReport :: String -> RegistryProblem -> String -> Help.Report
758+toRegistryProblemReport title problem context =
759+ case problem of
760+ RP_Http err ->
761+ toHttpErrorReport title err context
762+
763+ RP_Data url body ->
764+ Help.report title Nothing (context ++ ", so I fetched:")
765+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
766+ , D.reflow $
767+ "I got the data back, but it was not what I was expecting. The response\
768+ \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
769+ ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
770+ , D.indent 4 $ D.dullyellow $ D.fromChars $
771+ if BS.length body <= 76
772+ then BS_UTF8.toString body
773+ else take 73 (BS_UTF8.toString body) ++ "..."
774+ , D.reflow $
775+ "Does this error keep showing up? Maybe there is something weird with your\
776+ \ internet connection. We have gotten reports that schools, businesses,\
777+ \ airports, etc. sometimes intercept requests and add things to the body\
778+ \ or change its contents entirely. Could that be the problem?"
779+ ]
780+
781+
782+toHttpErrorReport :: String -> Http.Error -> String -> Help.Report
783+toHttpErrorReport title err context =
784+ let
785+ toHttpReport intro url details =
786+ Help.report title Nothing intro $
787+ D.indent 4 (D.dullyellow (D.fromChars url)) : details
788+ in
789+ case err of
790+ Http.BadUrl url reason ->
791+ toHttpReport (context ++ ", so I wanted to fetch:") url
792+ [ D.reflow $ "But my HTTP library is saying this is not a valid URL. It is saying:"
793+ , D.indent 4 $ D.fromChars reason
794+ , D.reflow $
795+ "This may indicate that there is some problem in the compiler, so please open an\
796+ \ issue at https://github.com/elm/compiler/issues listing your operating system\
797+ \ version, the command you ran, the terminal output, and any additional information\
798+ \ that might help others reproduce the error."
799+ ]
800+
801+ Http.BadHttp url httpExceptionContent ->
802+ case httpExceptionContent of
803+ HTTP.StatusCodeException response _ ->
804+ let
805+ (HTTP.Status code message) = HTTP.responseStatus response
806+ in
807+ toHttpReport (context ++ ", so I tried to fetch:") url
808+ [ D.fillSep $
809+ ["But","it","came","back","as",D.red (D.fromInt code)]
810+ ++ map D.fromChars (words (BS_UTF8.toString message))
811+ , D.reflow $
812+ "This may mean some online endpoint changed in an unexpected way, so if does not\
813+ \ seem like something on your side is causing this (e.g. firewall) please report\
814+ \ this to https://github.com/elm/compiler/issues with your operating system, Elm\
815+ \ version, the command you ran, the terminal output, and any additional information\
816+ \ that can help others reproduce the error!"
817+ ]
818+
819+ HTTP.TooManyRedirects responses ->
820+ toHttpReport (context ++ ", so I tried to fetch:") url
821+ [ D.reflow $ "But I gave up after following these " ++ show (length responses) ++ " redirects:"
822+ , D.indent 4 $ D.vcat $ map toRedirectDoc responses
823+ , D.reflow $
824+ "Is it possible that your internet connection intercepts certain requests? That\
825+ \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
826+ \ and certain countries. Try asking for help locally or in a community forum!"
827+ ]
828+
829+ otherException ->
830+ toHttpReport (context ++ ", so I tried to fetch:") url
831+ [ D.reflow $ "But my HTTP library is giving me the following error message:"
832+ , D.indent 4 $ D.fromChars (show otherException)
833+ , D.reflow $
834+ "Are you somewhere with a slow internet connection? Or no internet?\
835+ \ Does the link I am trying to fetch work in your browser? Maybe the\
836+ \ site is down? Does your internet connection have a firewall that\
837+ \ blocks certain domains? It is usually something like that!"
838+ ]
839+
840+ Http.BadMystery url someException ->
841+ toHttpReport (context ++ ", so I tried to fetch:") url
842+ [ D.reflow $ "But I ran into something weird! I was able to extract this error message:"
843+ , D.indent 4 $ D.fromChars (show someException)
844+ , D.reflow $
845+ "Is it possible that your internet connection intercepts certain requests? That\
846+ \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
847+ \ and certain countries. Try asking for help locally or in a community forum!"
848+ ]
849+
850+
851+toRedirectDoc :: HTTP.Response body -> D.Doc
852+toRedirectDoc response =
853+ let
854+ (HTTP.Status code message) = HTTP.responseStatus response
855+ in
856+ case List.lookup HTTP.hLocation (HTTP.responseHeaders response) of
857+ Just loc -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString loc)
858+ Nothing -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString message)
859+
860+
861+
730862-- MAKE
731863
732864
@@ -818,7 +950,8 @@ detailsToReport details =
818950 toOutlineReport outline
819951
820952 DetailsCannotGetRegistry problem ->
821− error "TODO DetailsCannotGetRegistry" problem
953+ toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
954+ "I need the list of published packages to figure out if your project has compatible dependencies"
822955
823956 DetailsCannotBuildPackage name version problem ->
824957 error "TODO DetailsCannotBuildPackage" name version problem
@@ -949,13 +1082,14 @@ toOutlineReport :: Outline -> Help.Report
9491082toOutlineReport problem =
9501083 case problem of
9511084 OutlineHasBadStructure decodeError ->
952− Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError
1085+ Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError $
1086+ Json.ExplicitReason "I ran into a problem with your elm.json file."
9531087
9541088 OutlineHasBadSrcDirs dir dirs ->
9551089 case dirs of
9561090 [] ->
9571091 Help.report "MISSING SOURCE DIRECTORY" (Just "elm.json")
958− "The \"source-directories\" in your elm.json lists the following directory:"
1092+ "I need a valid elm.json file, but the \"source-directories\" field lists the following directory:"
9591093 [ D.indent 4 $ D.dullyellow $ D.fromChars dir
9601094 , D.reflow $
9611095 "I cannot find it though. Is it missing? Is there a typo?"
@@ -963,7 +1097,7 @@ toOutlineReport problem =
9631097
9641098 _:_ ->
9651099 Help.report "MISSING SOURCE DIRECTORIES" (Just "elm.json")
966− "The \"source-directories\" in your elm.json lists the following directories:"
1100+ "I need a valid elm.json file, but the \"source-directories\" field lists the following directories:"
9671101 [ D.indent 4 $ D.dullyellow $ D.fromChars dir
9681102 , D.reflow $
9691103 "I cannot find them though. Are they missing? Are there typos?"
@@ -971,21 +1105,21 @@ toOutlineReport problem =
9711105
9721106 OutlineNoPkgCore ->
9731107 Help.report "MISSING DEPENDENCY" (Just "elm.json")
974− "A package must have \"elm/core\" as a dependency. Try running:"
1108+ "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
9751109 [ D.indent 4 $ D.green $ "elm install elm/core"
9761110 , D.reflow "I need it for the default imports that make `List` and `Maybe` available."
9771111 ]
9781112
9791113 OutlineNoAppCore ->
9801114 Help.report "MISSING DEPENDENCY" (Just "elm.json")
981− "An application must have \"elm/core\" as a dependency. Try running:"
1115+ "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
9821116 [ D.indent 4 $ D.green $ "elm install elm/core"
9831117 , D.reflow "It has some supporting code that is needed by every Elm application!"
9841118 ]
9851119
9861120 OutlineNoAppJson ->
9871121 Help.report "MISSING DEPENDENCY" (Just "elm.json")
988− "An application must have \"elm/json\" as a dependency. Try running:"
1122+ "I need a valid elm.json file, so I need to see an \"elm/json\" dependency in there. Try running:"
9891123 [ D.indent 4 $ D.green $ "elm install elm/json"
9901124 , D.reflow "It helps me handle flags and ports."
9911125 ]
@@ -1005,9 +1139,9 @@ toOutlineProblemReport path source _ region problem =
10051139 OP_BadType ->
10061140 toSnippet "UNEXPECTED TYPE" Nothing
10071141 ( D.reflow $
1008− "I do not know how to process this type of elm.json file:"
1142+ "I got stuck while reading your elm.json file. I cannot handle a \"type\" like this:"
10091143 , D.fillSep
1010− ["Try","changing","the","type","to"
1144+ ["Try","changing","the","\"type\"","to"
10111145 ,D.green "\"application\"","or",D.green "\"package\"","instead."
10121146 ]
10131147 )
@@ -1015,7 +1149,7 @@ toOutlineProblemReport path source _ region problem =
10151149 OP_BadPkgName row col ->
10161150 toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
10171151 ( D.reflow $
1018− "I ran into trouble with this package name:"
1152+ "I got stuck while reading your elm.json file. I ran into trouble with the package name:"
10191153 , D.stack
10201154 [ D.fillSep
10211155 ["Package","names","are","always","written","as"
@@ -1053,7 +1187,7 @@ toOutlineProblemReport path source _ region problem =
10531187 OP_BadVersion row col ->
10541188 toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
10551189 ( D.reflow $
1056− "I was expecting a version number here:"
1190+ "I got stuck while reading your elm.json file. I was expecting a version number here:"
10571191 , D.fillSep
10581192 ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
10591193 ,"that","explicitly","states","all","three","numbers!"
@@ -1065,7 +1199,7 @@ toOutlineProblemReport path source _ region problem =
10651199 C.BadFormat row col ->
10661200 toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
10671201 ( D.reflow $
1068− "I was expecting a version constraint here:"
1202+ "I got stuck while reading your elm.json file. I do not understand this version constraint:"
10691203 , D.stack
10701204 [ D.fillSep
10711205 ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
@@ -1082,7 +1216,7 @@ toOutlineProblemReport path source _ region problem =
10821216 if before == after then
10831217 toSnippet "PROBLEM WITH CONSTRAINT" Nothing
10841218 ( D.reflow $
1085− "I ran into an invalid version constraint:"
1219+ "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
10861220 , D.fillSep
10871221 ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
10881222 ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
@@ -1095,7 +1229,7 @@ toOutlineProblemReport path source _ region problem =
10951229 else
10961230 toSnippet "PROBLEM WITH CONSTRAINT" Nothing
10971231 ( D.reflow $
1098− "I ran into an invalid version constraint:"
1232+ "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
10991233 , D.fillSep
11001234 ["Maybe","you","want","something","like"
11011235 ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
@@ -1108,7 +1242,7 @@ toOutlineProblemReport path source _ region problem =
11081242 OP_BadModuleName row col ->
11091243 toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
11101244 ( D.reflow $
1111− "I was expecting a module name here:"
1245+ "I got stuck while reading your elm.json file. I was expecting a module name here:"
11121246 , D.fillSep
11131247 ["I","need","something","like",D.green "\"Html.Events\""
11141248 ,"or",D.green "\"Browser.Navigation\""
@@ -1120,7 +1254,7 @@ toOutlineProblemReport path source _ region problem =
11201254 OP_BadModuleHeaderTooLong ->
11211255 toSnippet "HEADER TOO LONG" Nothing
11221256 ( D.reflow $
1123− "This section header is too long:"
1257+ "I got stuck while reading your elm.json file. This section header is too long:"
11241258 , D.fillSep
11251259 ["I","need","it","to","be"
11261260 ,D.green "under",D.green "20",D.green "characters"
@@ -1131,7 +1265,7 @@ toOutlineProblemReport path source _ region problem =
11311265 OP_BadDependencyName row col ->
11321266 toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
11331267 ( D.reflow $
1134− "There is something wrong with this dependency name:"
1268+ "I got stuck while reading your elm.json file. There is something wrong with this dependency name:"
11351269 , D.stack
11361270 [ D.fillSep
11371271 ["Package","names","always","include","the","name","of","the","author,"
@@ -1150,7 +1284,7 @@ toOutlineProblemReport path source _ region problem =
11501284 OP_BadLicense _ suggestions ->
11511285 toSnippet "UNKNOWN LICENSE" Nothing
11521286 ( D.reflow $
1153− "I do not know about this type of license:"
1287+ "I got stuck while reading your elm.json file. I do not know about this type of license:"
11541288 ,
11551289 D.stack
11561290 [ D.fillSep
@@ -1168,7 +1302,7 @@ toOutlineProblemReport path source _ region problem =
11681302 OP_BadSummaryTooLong ->
11691303 toSnippet "SUMMARY TOO LONG" Nothing
11701304 ( D.reflow $
1171− "Your \"summary\" is too long:"
1305+ "I got stuck while reading your elm.json file. Your \"summary\" is too long:"
11721306 , D.fillSep
11731307 ["I","need","it","to","be"
11741308 ,D.green "under",D.green "80",D.green "characters"
@@ -1179,7 +1313,7 @@ toOutlineProblemReport path source _ region problem =
11791313 OP_NoSrcDirs ->
11801314 toSnippet "NO SOURCE DIRECTORIES" Nothing
11811315 ( D.reflow $
1182− "You do not have any \"source-directories\" listed here:"
1316+ "I got stuck while reading your elm.json file. You do not have any \"source-directories\" listed here:"
11831317 , D.fillSep
11841318 ["I","need","something","like",D.green "[\"src\"]"
11851319 ,"so","I","know","where","to","look","for","your","modules!"