@@ -1,37 +1,26 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Reporting.Exit
3− ( Init(..)
4− , initToReport
5− --
6− , Diff(..)
7− , diffToReport
8− --
9− , Bump(..)
10− , bumpToReport
3+ ( Init(..), initToReport
4+ , Diff(..), diffToReport
5+ , Make(..), makeToReport
6+ , Bump(..), bumpToReport
7+ , Repl(..), replToReport
8+ , Publish(..), publishToReport
9+ , Install(..), installToReport
10+ , Reactor(..), reactorToReport
1111 , newPackageOverview
1212 --
13− , Publish(..)
14− , publishToReport
15− --
16− , Install(..)
17− , installToReport
18− --
1913 , Solver(..)
20− --
2114 , Outline(..)
2215 , OutlineProblem(..)
23− --
2416 , Details(..)
17+ , DetailsBadDep(..)
2518 , PackageProblem(..)
26− --
2719 , RegistryProblem(..)
28− --
29− , Make(..)
3020 , BuildProblem(..)
3121 , BuildProjectProblem(..)
32− , makeToReport
33− --
3422 , DocsProblem(..)
23+ , Generate(..)
3524 --
3625 , toString
3726 , toStderr
@@ -43,16 +32,21 @@ module Reporting.Exit
4332import qualified Data.ByteString as BS
4433import qualified Data.ByteString.UTF8 as BS_UTF8
4534import qualified Data.List as List
35+import qualified Data.Map as Map
36+import qualified Data.Name as N
4637import qualified Data.NonEmptyList as NE
4738import qualified Network.HTTP.Client as HTTP
4839import qualified Network.HTTP.Types.Header as HTTP
4940import qualified Network.HTTP.Types.Status as HTTP
41+import qualified System.FilePath as FP
42+import System.FilePath ((</>), (<.>))
5043
5144import qualified Elm.Constraint as C
5245import qualified Elm.Magnitude as M
5346import qualified Elm.ModuleName as ModuleName
5447import qualified Elm.Package as Pkg
5548import qualified Elm.Version as V
49+import qualified File
5650import qualified Http
5751import qualified Json.Decode as Decode
5852import qualified Json.Encode as Encode
@@ -69,6 +63,25 @@ import qualified Reporting.Render.Code as Code
6963
7064
7165
66+-- RENDERERS
67+
68+
69+toString :: Help.Report -> String
70+toString report =
71+ Help.toString (Help.reportToDoc report)
72+
73+
74+toStderr :: Help.Report -> IO ()
75+toStderr report =
76+ Help.toStderr (Help.reportToDoc report)
77+
78+
79+toJson :: Help.Report -> Encode.Value
80+toJson report =
81+ Help.reportToJson report
82+
83+
84+
7285-- INIT
7386
7487
@@ -96,13 +109,18 @@ initToReport exit =
96109
97110 InitNoOfflineSolution pkgs ->
98111 Help.report "NO OFFLINE SOLUTION" Nothing
99− (error "TODO InitNoOfflineSolution" pkgs)
100− (error "TODO InitNoOfflineSolution" pkgs)
101− -- note about Russia IP addresses?
102− -- ask if they are on a plane or train
112+ "I tried to create an elm.json with the following direct dependencies:"
113+ [ D.indent 4 $ D.vcat $
114+ map (D.dullyellow . D.fromChars . Pkg.toChars) pkgs
115+ , D.reflow $
116+ "I could not find compatible versions though, but that may be because I could not\
117+ \ connect to https://package.elm-lang.org to get the latest list of packages. Are\
118+ \ you able to connect to the internet? Please ask around one of the community\
119+ \ forums at https://elm-lang.org/community for help!"
120+ ]
103121
104122 InitSolverProblem solver ->
105− error "TODO InitSolverProblem" solver
123+ toSolverReport solver
106124
107125 InitAlreadyExists ->
108126 Help.report "EXISTING PROJECT" Nothing
@@ -126,11 +144,11 @@ data Diff
126144 = DiffNoOutline
127145 | DiffBadOutline Outline
128146 | DiffApplication
129− | DiffNoExposed Pkg.Name
147+ | DiffNoExposed
130148 | DiffUnpublished
131149 | DiffUnknownPackage Pkg.Name [Pkg.Name]
132150 | DiffUnknownVersion Pkg.Name V.Version [V.Version]
133− | DiffDocsProblem DocsProblem
151+ | DiffDocsProblem V.Version DocsProblem
134152 | DiffMustHaveLatestRegistry RegistryProblem
135153 | DiffBadDetails Details
136154 | DiffBadBuild BuildProblem
@@ -156,14 +174,16 @@ diffToReport diff =
156174 \ with packages. That way there are previously published versions of the API to\
157175 \ diff against!"
158176 [ D.reflow $ "If you are just curious to see a diff, try running this command:"
159− , D.indent 4 $ D.dullyellow $ "elm diff elm/http 1.0.0 2.0.0"
177+ , D.indent 4 $ D.dullyellow $ "elm diff elm/json 1.0.0 1.1.2"
160178 ]
161179
162− DiffNoExposed pkg ->
180+ DiffNoExposed ->
163181 Help.report "NO EXPOSED MODULES" (Just "elm.json")
164182 "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− []
183+ \ all right now! What am I supposed to diff?"
184+ [ D.reflow $
185+ "Try adding some modules back to the \"exposed-modules\" field."
186+ ]
167187
168188 DiffUnpublished ->
169189 Help.report "UNPUBLISHED" Nothing
@@ -198,18 +218,19 @@ diffToReport diff =
198218 , "Want one of those instead?"
199219 ]
200220
201− DiffDocsProblem problem ->
202− error "TODO DiffDocsProblem" problem
221+ DiffDocsProblem version problem ->
222+ toDocsProblemReport problem $
223+ "I need the docs for " ++ V.toChars version ++ " to compute this diff"
203224
204225 DiffMustHaveLatestRegistry problem ->
205226 toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
206227 "I need the latest list of published packages before I do this diff"
207228
208229 DiffBadDetails details ->
209− error "TODO DiffBadDetails" details
230+ toDetailsReport details
210231
211232 DiffBadBuild buildProblem ->
212− error "TODO DiffBadBuild" buildProblem
233+ toBuildProblemReport buildProblem
213234
214235
215236
@@ -223,6 +244,9 @@ data Bump
223244 | BumpUnexpectedVersion V.Version [V.Version]
224245 | BumpMustHaveLatestRegistry RegistryProblem
225246 | BumpCannotFindDocs Pkg.Name V.Version DocsProblem
247+ | BumpBadDetails Details
248+ | BumpNoExposed
249+ | BumpBadBuild BuildProblem
226250
227251
228252bumpToReport :: Bump -> Help.Report
@@ -266,8 +290,27 @@ bumpToReport bump =
266290 toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
267291 "I need the latest list of published packages before I can bump any versions"
268292
269− BumpCannotFindDocs name version problem ->
270− error "TODO BumpCannotFindDocs" name version problem
293+ BumpCannotFindDocs _ version problem ->
294+ toDocsProblemReport problem $
295+ "I need the docs for " ++ V.toChars version ++ " to compute the next version number"
296+
297+ BumpBadDetails details ->
298+ toDetailsReport details
299+
300+ BumpNoExposed ->
301+ Help.docReport "NO EXPOSED MODULES" (Just "elm.json")
302+ ( D.fillSep $
303+ [ "To", "bump", "a", "package,", "the"
304+ , D.dullyellow "\"exposed-modules\"", "field", "of", "your"
305+ , "elm.json", "must", "list", "at", "least", "one", "module."
306+ ]
307+ )
308+ [ D.reflow $
309+ "Try adding some modules back to the \"exposed-modules\" field."
310+ ]
311+
312+ BumpBadBuild problem ->
313+ toBuildProblemReport problem
271314
272315
273316
@@ -314,12 +357,13 @@ data Publish
314357 | PublishShortReadme
315358 | PublishNoLicense
316359 | PublishBuildProblem BuildProblem
317− | PublishCannotGetTag Http.Error
360+ | PublishMissingTag V.Version
361+ | PublishCannotGetTag V.Version Http.Error
362+ | PublishCannotGetTagData V.Version String BS.ByteString
318363 | PublishCannotGetZip Http.Error
319− | PublishCannotDecodeZip
320− | PublishCannotGetDocs DocsProblem
364+ | PublishCannotDecodeZip String
365+ | PublishCannotGetDocs V.Version V.Version DocsProblem
321366 | PublishCannotRegister Http.Error
322− | PublishMissingTag V.Version
323367 | PublishNoGit
324368 | PublishLocalChanges V.Version
325369 --
@@ -344,7 +388,7 @@ publishToReport publish =
344388 toOutlineReport outline
345389
346390 PublishBadDetails problem ->
347− error "TODO PublishBadDetails" problem
391+ toDetailsReport problem
348392
349393 PublishMustHaveLatestRegistry problem ->
350394 toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
@@ -453,7 +497,8 @@ publishToReport publish =
453497 ]
454498 )
455499 [ D.reflow $
456− "What is the point of a package that has no modules?!"
500+ "Which modules do you want users of the package to have access to? Add their\
501+ \ names to the \"exposed-modules\" list."
457502 ]
458503
459504 PublishNoReadme ->
@@ -480,22 +525,7 @@ publishToReport publish =
480525 ]
481526
482527 PublishBuildProblem buildProblem ->
483− error "TODO PublishBuildProblem" buildProblem
484−
485− PublishCannotGetTag httpError ->
486− error "TODO PublishCannotGetTag" httpError
487−
488− PublishCannotGetZip httpError ->
489− error "TODO PublishCannotGetZip" httpError
490−
491− PublishCannotDecodeZip ->
492− error "TODO PublishCannotDecodeZip"
493−
494− PublishCannotGetDocs docsProblem ->
495− error "TODO PublishCannotGetDocs" docsProblem
496−
497− PublishCannotRegister httpError ->
498− error "TODO PublishCannotRegister" httpError
528+ toBuildProblemReport buildProblem
499529
500530 PublishMissingTag version ->
501531 let vsn = V.toChars version in
@@ -516,6 +546,70 @@ publishToReport publish =
516546 , "The -m flag is for a helpful message. Try to make it more informative!"
517547 ]
518548
549+ PublishCannotGetTag version httpError ->
550+ case httpError of
551+ Http.BadHttp _ (HTTP.StatusCodeException response _)
552+ | HTTP.statusCode (HTTP.responseStatus response) == 404 ->
553+ let vsn = V.toChars version in
554+ Help.report "NO TAG ON GITHUB" Nothing
555+ ("You have version " ++ vsn ++ " tagged locally, but not on GitHub.")
556+ [ D.reflow
557+ "Run the following command to make this tag available on GitHub:"
558+ , D.indent 4 $ D.dullyellow $ D.fromChars $
559+ "git push origin " ++ vsn
560+ , D.reflow
561+ "This will make it possible to find your code online based on the version number."
562+ ]
563+
564+ _ ->
565+ toHttpErrorReport "PROBLEM VERIFYING TAG" httpError
566+ "I need to check that the version tag is registered on GitHub"
567+
568+ PublishCannotGetTagData version url body ->
569+ Help.report "PROBLEM VERIFYING TAG" Nothing
570+ ("I need to check that version " ++ V.toChars version ++ " is tagged on GitHub, so I fetched:")
571+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
572+ , D.reflow $
573+ "I got the data back, but it was not what I was expecting. The response\
574+ \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
575+ ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
576+ , D.indent 4 $ D.dullyellow $ D.fromChars $
577+ if BS.length body <= 76
578+ then BS_UTF8.toString body
579+ else take 73 (BS_UTF8.toString body) ++ "..."
580+ , D.reflow $
581+ "Does this error keep showing up? Maybe there is something weird with your\
582+ \ internet connection. We have gotten reports that schools, businesses,\
583+ \ airports, etc. sometimes intercept requests and add things to the body\
584+ \ or change its contents entirely. Could that be the problem?"
585+ ]
586+
587+ PublishCannotGetZip httpError ->
588+ toHttpErrorReport "PROBLEM DOWNLOADING CODE" httpError $
589+ "I need to check that folks can download and build the source code when they\
590+ \ install this package"
591+
592+ PublishCannotDecodeZip url ->
593+ Help.report "PROBLEM DOWNLOADING CODE" Nothing
594+ "I need to check that folks can download and build the source code when they\
595+ \ install this package, so I downloaded the code from:"
596+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
597+ , D.reflow $
598+ "I was unable to unzip the archive though. Maybe there is something weird with\
599+ \ your internet connection. We have gotten reports that schools, businesses,\
600+ \ airports, etc. sometimes intercept requests and add things to the body or\
601+ \ change its contents entirely. Could that be the problem?"
602+ ]
603+
604+ PublishCannotGetDocs old new docsProblem ->
605+ toDocsProblemReport docsProblem $
606+ "I need the docs for " ++ V.toChars old ++ " to verify that "
607+ ++ V.toChars new ++ " really does come next"
608+
609+ PublishCannotRegister httpError ->
610+ toHttpErrorReport "PROBLEM PUBLISHING PACKAGE" httpError $
611+ "I need to send information about your package to the package website"
612+
519613 PublishNoGit ->
520614 Help.report "NO GIT" Nothing
521615 "I searched your PATH environment variable for `git` and could not\
@@ -545,17 +639,17 @@ publishToReport publish =
545639 ++ vsn ++ "` and publish your code from there."
546640 ]
547641
548− PublishZipBadDetails details ->
549− error "TODO PublishZipBadDetails" details
642+ PublishZipBadDetails _ ->
643+ badZipReport
550644
551645 PublishZipApplication ->
552− error "TODO PublishZipApplication"
646+ badZipReport
553647
554648 PublishZipNoExposed ->
555− error "TODO PublishZipNoExposed"
649+ badZipReport
556650
557− PublishZipBuildProblem buildProblem ->
558− error "TODO PublishZipBuildProblem" buildProblem
651+ PublishZipBuildProblem _ ->
652+ badZipReport
559653
560654
561655toBadReadmeReport :: String -> String -> Help.Report
@@ -572,12 +666,24 @@ toBadReadmeReport title summary =
572666 \ most common usage scenario. Show people what they can expect if\
573667 \ they learn more!"
574668 , D.toSimpleNote $
575− "By publishing your package, you are inviting people to invest time\
576− \ in understanding your work. Spending an hour to communicate your\
577− \ knowledge more clearly can save the community days or weeks of time\
578− \ in aggregate, and saving time in aggregate is the whole point of\
579− \ publishing packages! People really appreciate it, and it makes the\
580− \ whole ecosystem feel nicer!"
669+ "By publishing your package, you are inviting people to invest time in\
670+ \ understanding your work. Spending an hour on your README to communicate your\
671+ \ knowledge more clearly can save the community days or weeks of time in\
672+ \ aggregate, and saving time in aggregate is the whole point of publishing\
673+ \ packages! People really appreciate it, and it makes the whole ecosystem feel\
674+ \ nicer!"
675+ ]
676+
677+
678+badZipReport :: Help.Report
679+badZipReport =
680+ Help.report "PROBLEM VERIFYING PACKAGE" Nothing
681+ "Before publishing packages, I download the code from GitHub and try to build it\
682+ \ from scratch. That way I can be more confident that it will work for other\
683+ \ people too. But I am not able to build it!"
684+ [ D.reflow $
685+ "I was just able to build your local copy though. Is there some way the version\
686+ \ on GitHub could be different?"
581687 ]
582688
583689
@@ -587,35 +693,80 @@ toBadReadmeReport title summary =
587693
588694data DocsProblem
589695 = DP_Http Http.Error
590− | DP_Data
696+ | DP_Data String BS.ByteString
591697 | DP_Cache
592698
593699
700+toDocsProblemReport :: DocsProblem -> String -> Help.Report
701+toDocsProblemReport problem context =
702+ case problem of
703+ DP_Http httpError ->
704+ toHttpErrorReport "PROBLEM LOADING DOCS" httpError context
705+
706+ DP_Data url body ->
707+ Help.report "PROBLEM LOADING DOCS" Nothing (context ++ ", so I fetched:")
708+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
709+ , D.reflow $
710+ "I got the data back, but it was not what I was expecting. The response\
711+ \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
712+ ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
713+ , D.indent 4 $ D.dullyellow $ D.fromChars $
714+ if BS.length body <= 76
715+ then BS_UTF8.toString body
716+ else take 73 (BS_UTF8.toString body) ++ "..."
717+ , D.reflow $
718+ "Does this error keep showing up? Maybe there is something weird with your\
719+ \ internet connection. We have gotten reports that schools, businesses,\
720+ \ airports, etc. sometimes intercept requests and add things to the body\
721+ \ or change its contents entirely. Could that be the problem?"
722+ ]
723+
724+ DP_Cache ->
725+ Help.report "PROBLEM LOADING DOCS" Nothing (context ++ ", but the local copy seems to be corrupted.")
726+ [ D.reflow $
727+ "I deleted the cached version, so the next run should download a fresh copy of\
728+ \ the docs. Hopefully that will get you unstuck, but it will not resolve the root\
729+ \ problem if, for example, a 3rd party editor plugin is modifing cached files\
730+ \ for some reason."
731+ ]
732+
733+
594734
595735-- INSTALL
596736
597737
598738data Install
599− = InstallNoProject
739+ = InstallNoOutline
740+ | InstallBadOutline Outline
741+ | InstallBadRegistry RegistryProblem
600742 | InstallNoArgs FilePath
601− | InstallNoOnlineSolution
602− | InstallNoOfflineSolution
743+ | InstallNoOnlineAppSolution Pkg.Name
744+ | InstallNoOfflineAppSolution Pkg.Name
745+ | InstallNoOnlinePkgSolution Pkg.Name
746+ | InstallNoOfflinePkgSolution Pkg.Name
603747 | InstallHadSolverTrouble Solver
604− | InstallUnknownPackageOnline [Pkg.Name]
605− | InstallUnknownPackageOffline [Pkg.Name]
606− | InstallHasBadDetails Details
748+ | InstallUnknownPackageOnline Pkg.Name [Pkg.Name]
749+ | InstallUnknownPackageOffline Pkg.Name [Pkg.Name]
750+ | InstallBadDetails Details
607751
608752
609753installToReport :: Install -> Help.Report
610754installToReport exit =
611755 case exit of
612− InstallNoProject ->
756+ InstallNoOutline ->
613757 Help.report "NEW PROJECT?" Nothing
614758 "Are you trying to start a new project? Try this command instead:"
615759 [ D.indent 4 $ D.green "elm init"
616760 , D.reflow "It will help you get started!"
617761 ]
618762
763+ InstallBadOutline outline ->
764+ toOutlineReport outline
765+
766+ InstallBadRegistry problem ->
767+ toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
768+ "I need the list of published packages to figure out how to install things"
769+
619770 InstallNoArgs elmHome ->
620771 Help.report "INSTALL WHAT?" Nothing
621772 "I am expecting commands like:"
@@ -639,50 +790,109 @@ installToReport exit =
639790 ]
640791 ]
641792
642− InstallNoOnlineSolution ->
643− Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json") -- TODO recommend using solver in `elm reactor`
644− "This usually happens if you try to modify dependency constraints by\
645− \ hand. I recommend deleting any dependency you added recently (or all\
646− \ of them if things are bad) and then adding them again with:"
647− [ D.indent 4 $ D.green "elm install"
793+ InstallNoOnlineAppSolution pkg ->
794+ Help.report "CANNOT FIND COMPATIBLE VERSION" (Just "elm.json")
795+ (
796+ "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
797+ \ with your existing dependencies."
798+ )
799+ [ D.reflow $
800+ "I checked all the published versions. When that failed, I tried to find any\
801+ \ compatible combination of these packages, even if it meant changing all your\
802+ \ existing dependencies! That did not work either!"
648803 , D.reflow $
649− "And do not be afaid to ask for help on Slack if you get stuck!"
804+ "This is most likely to happen when a package is not upgraded yet. Maybe a new\
805+ \ version of Elm came out recently? Maybe a common package was changed recently?\
806+ \ Maybe a better package came along, so there was no need to upgrade this one?\
807+ \ Try asking around https://elm-lang.org/community to learn what might be going on\
808+ \ with this package."
809+ , D.toSimpleNote $
810+ "Whatever the case, please be kind to the relevant package authors! Having\
811+ \ friendly interactions with users is great motivation, and conversely, getting\
812+ \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
813+ \ authors are humans with families, friends, jobs, vacations, responsibilities,\
814+ \ goals, etc. They face obstacles outside of their technical work you will never\
815+ \ know about, so please assume the best and try to be patient and supportive!"
650816 ]
651817
652− InstallNoOfflineSolution ->
653− error "TODO InstallNoOfflineSolution"
818+ InstallNoOfflineAppSolution pkg ->
819+ Help.report "CANNOT FIND COMPATIBLE VERSION LOCALLY" (Just "elm.json")
820+ (
821+ "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
822+ \ with your existing dependencies."
823+ )
824+ [ D.reflow $
825+ "I was not able to connect to https://package.elm-lang.org/ though, so I was only\
826+ \ able to look through packages that you have downloaded in the past."
827+ , D.reflow $
828+ "Try again later when you have internet!"
829+ ]
654830
655− InstallHadSolverTrouble solver ->
656− error "TODO InstallHadSolverTrouble" solver
831+ InstallNoOnlinePkgSolution pkg ->
832+ Help.report "CANNOT FIND COMPATIBLE VERSION" (Just "elm.json")
833+ (
834+ "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
835+ \ with your existing constraints."
836+ )
837+ [ D.reflow $
838+ "With applications, I try to broaden the constraints to see if anything works,\
839+ \ but messing with package constraints is much more delicate business. E.g. making\
840+ \ your constraints stricter may make it harder for applications to find compatible\
841+ \ dependencies. So fixing something here may break it for a lot of other people!"
842+ , D.reflow $
843+ "So I recommend making an application with the same dependencies as your package.\
844+ \ See if there is a solution at all. From there it may be easier to figure out\
845+ \ how to proceed in a way that will disrupt your users as little as possible. And\
846+ \ the solution may be to help other package authors to get their packages updated,\
847+ \ or to drop a dependency entirely."
848+ ]
657849
658− InstallUnknownPackageOnline suggestions ->
659− error "TODO InstallUnknownPackageOnline" suggestions
850+ InstallNoOfflinePkgSolution pkg ->
851+ Help.report "CANNOT FIND COMPATIBLE VERSION LOCALLY" (Just "elm.json")
852+ (
853+ "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
854+ \ with your existing constraints."
855+ )
856+ [ D.reflow $
857+ "I was not able to connect to https://package.elm-lang.org/ though, so I was only\
858+ \ able to look through packages that you have downloaded in the past."
859+ , D.reflow $
860+ "Try again later when you have internet!"
861+ ]
660862
661− InstallUnknownPackageOffline suggestions ->
662− error "TODO InstallUnknownPackageOffline" suggestions
863+ InstallHadSolverTrouble solver ->
864+ toSolverReport solver
663865
664− InstallHasBadDetails _ ->
665− error "TODO InstallHasBadDetails"
866+ InstallUnknownPackageOnline pkg suggestions ->
867+ Help.docReport "UNKNOWN PACKAGE" Nothing
868+ (
869+ D.fillSep
870+ ["I","cannot","find","a","package","named",D.red (D.fromPackage pkg) <> "."]
871+ )
872+ [ D.reflow $
873+ "I looked through https://package.elm-lang.org for packages with similar names\
874+ \ and found these:"
875+ , D.indent 4 $ D.dullyellow $ D.vcat $ map D.fromPackage suggestions
876+ , D.reflow $ "Maybe you want one of these instead?"
877+ ]
666878
879+ InstallUnknownPackageOffline pkg suggestions ->
880+ Help.docReport "UNKNOWN PACKAGE" Nothing
881+ (
882+ D.fillSep
883+ ["I","cannot","find","a","package","named",D.red (D.fromPackage pkg) <> "."]
884+ )
885+ [ D.reflow $
886+ "I could not connect to https://package.elm-lang.org though, so new packages may\
887+ \ have been published since I last updated my local cache of package names."
888+ , D.reflow $
889+ "Looking through the locally cached names, the closest ones are:"
890+ , D.indent 4 $ D.dullyellow $ D.vcat $ map D.fromPackage suggestions
891+ , D.reflow $ "Maybe you want one of these instead?"
892+ ]
667893
668−{- TODO detect if library has no 0.19.0 version. Maybe do this on website though?
669− Help.report "OLD DEPENDENCIES" (Just "elm.json")
670− ( "The following packages do not work with Elm " ++ V.toChars V.compiler ++ " right now:"
671− )
672− [ D.indent 4 $ D.vcat $ map (D.red . D.fromPackage) badPackages
673− , D.reflow $
674− "This may be because it is not upgraded yet. It may be because a\
675− \ better solution came along, so there was no need to upgrade it.\
676− \ Etc. Try asking around on Slack to learn more about the topic."
677− , D.toSimpleNote
678− "Whatever the case, please be kind to the relevant package authors! Having\
679− \ friendly interactions with users is great motivation, and conversely, getting\
680− \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
681− \ authors are humans with families, friends, jobs, vacations, responsibilities,\
682− \ goals, etc. They face obstacles outside of their technical work you will never\
683− \ know about, so please assume the best and try to be patient and supportive!"
684− ]
685−-}
894+ InstallBadDetails details ->
895+ toDetailsReport details
686896
687897
688898
@@ -691,8 +901,44 @@ installToReport exit =
691901
692902data Solver
693903 = SolverBadCacheData Pkg.Name V.Version
694− | SolverBadHttpData Pkg.Name V.Version
695− | SolverBadHttp Http.Error
904+ | SolverBadHttpData Pkg.Name V.Version String
905+ | SolverBadHttp Pkg.Name V.Version Http.Error
906+
907+
908+toSolverReport :: Solver -> Help.Report
909+toSolverReport problem =
910+ case problem of
911+ SolverBadCacheData pkg vsn ->
912+ Help.report "PROBLEM SOLVING PACKAGE CONSTRAINTS" Nothing
913+ (
914+ "I need the elm.json of " ++ Pkg.toChars pkg ++ " " ++ V.toChars vsn ++ " to\
915+ \ help me search for a set of compatible packages. I had it cached locally, but\
916+ \ it looks like the file was corrupted!"
917+ )
918+ [ D.reflow $
919+ "I deleted the cached version, so the next run should download a fresh copy.\
920+ \ Hopefully that will get you unstuck, but it will not resolve the root\
921+ \ problem if a 3rd party tool is modifing cached files for some reason."
922+ ]
923+
924+ SolverBadHttpData pkg vsn url ->
925+ Help.report "PROBLEM SOLVING PACKAGE CONSTRAINTS" Nothing
926+ (
927+ "I need the elm.json of " ++ Pkg.toChars pkg ++ " " ++ V.toChars vsn ++ " to\
928+ \ help me search for a set of compatible packages, but I ran into corrupted\
929+ \ information from:"
930+ )
931+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
932+ , D.reflow $
933+ "Is something weird with your internet connection. We have gotten reports that\
934+ \ schools, businesses, airports, etc. sometimes intercept requests and add things\
935+ \ to the body or change its contents entirely. Could that be the problem?"
936+ ]
937+
938+ SolverBadHttp pkg vsn httpError ->
939+ toHttpErrorReport "PROBLEM SOLVING PACKAGE CONSTRAINTS" httpError $
940+ "I need the elm.json of " ++ Pkg.toChars pkg ++ " " ++ V.toChars vsn
941+ ++ " to help me search for a set of compatible packages"
696942
697943
698944
@@ -701,7 +947,8 @@ data Solver
701947
702948data Outline
703949 = OutlineHasBadStructure (Decode.Error OutlineProblem)
704− | OutlineHasBadSrcDirs FilePath [FilePath]
950+ | OutlineHasMissingSrcDirs FilePath [FilePath]
951+ | OutlineHasDuplicateSrcDirs FilePath FilePath FilePath
705952 | OutlineNoPkgCore
706953 | OutlineNoAppCore
707954 | OutlineNoAppJson
@@ -720,94 +967,570 @@ data OutlineProblem
720967 | OP_NoSrcDirs
721968
722969
970+toOutlineReport :: Outline -> Help.Report
971+toOutlineReport problem =
972+ case problem of
973+ OutlineHasBadStructure decodeError ->
974+ Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError $
975+ Json.ExplicitReason "I ran into a problem with your elm.json file."
723976
724−-- DETAILS
725−
726−
727−data Details
728− = DetailsCorrupt
729− | DetailsNoSolution
730− | DetailsNoOfflineSolution
731− | DetailsSolverProblem Solver
732− | DetailsBadElmInPkg C.Constraint
733− | DetailsBadElmInAppOutline V.Version
734− | DetailsHandEditedDependencies
735− | DetailsBadOutline Outline
736− | DetailsCannotGetRegistry RegistryProblem
737− | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
738−
739−
740−data PackageProblem
741− = PP_BadEndpointRequest Http.Error
742− | PP_BadEndpointContent
743− | PP_BadArchiveRequest Http.Error
744− | PP_BadArchiveContent
745− | PP_BadArchiveHash String String
746−
747−
748−
749−-- REGISTRY PROBLEM
977+ OutlineHasMissingSrcDirs dir dirs ->
978+ case dirs of
979+ [] ->
980+ Help.report "MISSING SOURCE DIRECTORY" (Just "elm.json")
981+ "I need a valid elm.json file, but the \"source-directories\" field lists the following directory:"
982+ [ D.indent 4 $ D.red $ D.fromChars dir
983+ , D.reflow $
984+ "I cannot find it though. Is it missing? Is there a typo?"
985+ ]
750986
987+ _:_ ->
988+ Help.report "MISSING SOURCE DIRECTORIES" (Just "elm.json")
989+ "I need a valid elm.json file, but the \"source-directories\" field lists the following directories:"
990+ [ D.indent 4 $ D.vcat $
991+ map (D.red . D.fromChars) (dir:dirs)
992+ , D.reflow $
993+ "I cannot find them though. Are they missing? Are there typos?"
994+ ]
751995
752−data RegistryProblem
753− = RP_Http Http.Error
754− | RP_Data String BS.ByteString
996+ OutlineHasDuplicateSrcDirs canonicalDir dir1 dir2 ->
997+ if dir1 == dir2 then
998+ Help.report "REDUNDANT SOURCE DIRECTORIES" (Just "elm.json")
999+ "I need a valid elm.json file, but the \"source-directories\" field lists the same directory twice:"
1000+ [ D.indent 4 $ D.vcat $
1001+ map (D.red . D.fromChars) [dir1,dir2]
1002+ , D.reflow $
1003+ "Remove one of the entries!"
1004+ ]
1005+ else
1006+ Help.report "REDUNDANT SOURCE DIRECTORIES" (Just "elm.json")
1007+ "I need a valid elm.json file, but the \"source-directories\" field has some redundant directories:"
1008+ [ D.indent 4 $ D.vcat $
1009+ map (D.red . D.fromChars) [dir1,dir2]
1010+ , D.reflow $
1011+ "These are two different ways of refering to the same directory:"
1012+ , D.indent 4 $ D.dullyellow $ D.fromChars canonicalDir
1013+ , D.reflow $
1014+ "Remove one of the redundant entries from your \"source-directories\" field."
1015+ ]
7551016
1017+ OutlineNoPkgCore ->
1018+ Help.report "MISSING DEPENDENCY" (Just "elm.json")
1019+ "I need to see an \"elm/core\" dependency your elm.json file. The default imports\
1020+ \ of `List` and `Maybe` do not work without it."
1021+ [ D.reflow $
1022+ "If you modified your elm.json by hand, try to change it back! And if you are\
1023+ \ having trouble getting back to a working elm.json, it may be easier to find a\
1024+ \ working package and start fresh with their elm.json file."
1025+ ]
7561026
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
1027+ OutlineNoAppCore ->
1028+ Help.report "MISSING DEPENDENCY" (Just "elm.json")
1029+ "I need to see an \"elm/core\" dependency your elm.json file. The default imports\
1030+ \ of `List` and `Maybe` do not work without it."
1031+ [ D.reflow $
1032+ "If you modified your elm.json by hand, try to change it back! And if you are\
1033+ \ having trouble getting back to a working elm.json, it may be easier to delete it\
1034+ \ and use `elm init` to start fresh."
1035+ ]
7621036
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?"
1037+ OutlineNoAppJson ->
1038+ Help.report "MISSING DEPENDENCY" (Just "elm.json")
1039+ "I need to see an \"elm/json\" dependency your elm.json file. It helps me handle\
1040+ \ flags and ports."
1041+ [ D.reflow $
1042+ "If you modified your elm.json by hand, try to change it back! And if you are\
1043+ \ having trouble getting back to a working elm.json, it may be easier to delete it\
1044+ \ and use `elm init` to start fresh."
7791045 ]
7801046
7811047
782−toHttpErrorReport :: String -> Http.Error -> String -> Help.Report
783−toHttpErrorReport title err context =
1048+toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
1049+toOutlineProblemReport path source _ region problem =
7841050 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− ]
1051+ toHighlight row col =
1052+ Just $ A.Region (A.Position row col) (A.Position row col)
8001053
801− Http.BadHttp url httpExceptionContent ->
802− case httpExceptionContent of
803− HTTP.StatusCodeException response _ ->
804− let
1054+ toSnippet title highlight pair =
1055+ Help.jsonReport title (Just path) $
1056+ Code.toSnippet source region highlight pair
1057+ in
1058+ case problem of
1059+ OP_BadType ->
1060+ toSnippet "UNEXPECTED TYPE" Nothing
1061+ ( D.reflow $
1062+ "I got stuck while reading your elm.json file. I cannot handle a \"type\" like this:"
1063+ , D.fillSep
1064+ ["Try","changing","the","\"type\"","to"
1065+ ,D.green "\"application\"","or",D.green "\"package\"","instead."
1066+ ]
1067+ )
1068+
1069+ OP_BadPkgName row col ->
1070+ toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
1071+ ( D.reflow $
1072+ "I got stuck while reading your elm.json file. I ran into trouble with the package name:"
1073+ , D.stack
1074+ [ D.fillSep
1075+ ["Package","names","are","always","written","as"
1076+ ,D.green "\"author/project\""
1077+ ,"so","I","am","expecting","to","see","something","like:"
1078+ ]
1079+ , D.dullyellow $ D.indent 4 $ D.vcat $
1080+ [ "\"mdgriffith/elm-ui\""
1081+ , "\"w0rm/elm-physics\""
1082+ , "\"Microsoft/elm-json-tree-view\""
1083+ , "\"FordLabs/elm-star-rating\""
1084+ , "\"1602/json-schema\""
1085+ ]
1086+ , D.reflow
1087+ "The author name should match your GitHub name exactly, and the project name\
1088+ \ needs to follow these rules:"
1089+ , D.indent 4 $ D.vcat $
1090+ [ "+--------------------------------------+-----------+-----------+"
1091+ , "| RULE | BAD | GOOD |"
1092+ , "+--------------------------------------+-----------+-----------+"
1093+ , "| only lower case, digits, and hyphens | elm-HTTP | elm-http |"
1094+ , "| no leading digits | 3D | elm-3d |"
1095+ , "| no non-ASCII characters | elm-bjørn | elm-bear |"
1096+ , "| no underscores | elm_ui | elm-ui |"
1097+ , "| no double hyphens | elm--hash | elm-hash |"
1098+ , "| no starting or ending hyphen | -elm-tar- | elm-tar |"
1099+ , "+--------------------------------------+-----------+-----------+"
1100+ ]
1101+ , D.toSimpleNote $
1102+ "These rules only apply to the project name, so you should never need\
1103+ \ to change your GitHub name!"
1104+ ]
1105+ )
1106+
1107+ OP_BadVersion row col ->
1108+ toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
1109+ ( D.reflow $
1110+ "I got stuck while reading your elm.json file. I was expecting a version number here:"
1111+ , D.fillSep
1112+ ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
1113+ ,"that","explicitly","states","all","three","numbers!"
1114+ ]
1115+ )
1116+
1117+ OP_BadConstraint constraintError ->
1118+ case constraintError of
1119+ C.BadFormat row col ->
1120+ toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
1121+ ( D.reflow $
1122+ "I got stuck while reading your elm.json file. I do not understand this version constraint:"
1123+ , D.stack
1124+ [ D.fillSep
1125+ ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
1126+ ,"that","explicitly","lists","the","lower","and","upper","bounds."
1127+ ]
1128+ , D.toSimpleNote $
1129+ "The spaces in there are required! Taking them out will confuse me. Adding\
1130+ \ extra spaces confuses me too. I recommend starting with a valid example\
1131+ \ and just changing the version numbers."
1132+ ]
1133+ )
1134+
1135+ C.InvalidRange before after ->
1136+ if before == after then
1137+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1138+ ( D.reflow $
1139+ "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1140+ , D.fillSep
1141+ ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
1142+ ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
1143+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor after) <> "\""
1144+ ,"since","it","is","guaranteed","that","breaking","API","changes","cannot"
1145+ ,"happen","in","any","of","the","versions","in","that","range."
1146+ ]
1147+ )
1148+
1149+ else
1150+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1151+ ( D.reflow $
1152+ "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1153+ , D.fillSep
1154+ ["Maybe","you","want","something","like"
1155+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
1156+ ,"instead?","Elm","checks","that","all","package","APIs","follow","semantic"
1157+ ,"versioning,","so","it","is","guaranteed","that","breaking","API","changes"
1158+ ,"cannot","happen","in","any","of","the","versions","in","that","range."
1159+ ]
1160+ )
1161+
1162+ OP_BadModuleName row col ->
1163+ toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
1164+ ( D.reflow $
1165+ "I got stuck while reading your elm.json file. I was expecting a module name here:"
1166+ , D.fillSep
1167+ ["I","need","something","like",D.green "\"Html.Events\""
1168+ ,"or",D.green "\"Browser.Navigation\""
1169+ ,"where","each","segment","starts","with","a","capital"
1170+ ,"letter","and","the","segments","are","separated","by","dots."
1171+ ]
1172+ )
1173+
1174+ OP_BadModuleHeaderTooLong ->
1175+ toSnippet "HEADER TOO LONG" Nothing
1176+ ( D.reflow $
1177+ "I got stuck while reading your elm.json file. This section header is too long:"
1178+ , D.stack
1179+ [ D.fillSep
1180+ ["I","need","it","to","be"
1181+ ,D.green "under",D.green "20",D.green "bytes"
1182+ ,"so","it","renders","nicely","on","the","package","website!"
1183+ ]
1184+ , D.toSimpleNote
1185+ "I count the length in bytes, so using non-ASCII characters costs extra.\
1186+ \ Please report your case at https://github.com/elm/compiler/issues if this seems\
1187+ \ overly restrictive for your needs."
1188+ ]
1189+ )
1190+
1191+ OP_BadDependencyName row col ->
1192+ toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
1193+ ( D.reflow $
1194+ "I got stuck while reading your elm.json file. There is something wrong with this dependency name:"
1195+ , D.stack
1196+ [ D.fillSep
1197+ ["Package","names","always","include","the","name","of","the","author,"
1198+ ,"so","I","am","expecting","to","see","dependencies","like"
1199+ ,D.dullyellow "\"mdgriffith/elm-ui\"","and"
1200+ ,D.dullyellow "\"Microsoft/elm-json-tree-view\"" <> "."
1201+ ]
1202+ , D.fillSep $
1203+ ["I","generally","recommend","finding","the","package","you","want","on"
1204+ ,"the","package","website,","and","installing","it","with","the"
1205+ ,D.green "elm install","command!"
1206+ ]
1207+ ]
1208+ )
1209+
1210+ OP_BadLicense _ suggestions ->
1211+ toSnippet "UNKNOWN LICENSE" Nothing
1212+ ( D.reflow $
1213+ "I got stuck while reading your elm.json file. I do not know about this type of license:"
1214+ ,
1215+ D.stack
1216+ [ D.fillSep
1217+ ["Elm","packages","generally","use"
1218+ ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\"" <> ","
1219+ ,"but","I","accept","any","OSI","approved","SPDX","license."
1220+ ,"Here","some","that","seem","close","to","what","you","wrote:"
1221+ ]
1222+ , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Json.toChars) suggestions
1223+ , D.reflow $
1224+ "Check out https://spdx.org/licenses/ for the full list of options."
1225+ ]
1226+ )
1227+
1228+ OP_BadSummaryTooLong ->
1229+ toSnippet "SUMMARY TOO LONG" Nothing
1230+ ( D.reflow $
1231+ "I got stuck while reading your elm.json file. Your \"summary\" is too long:"
1232+ , D.stack
1233+ [ D.fillSep
1234+ ["I","need","it","to","be"
1235+ ,D.green "under",D.green "80",D.green "bytes"
1236+ ,"so","it","renders","nicely","on","the","package","website!"
1237+ ]
1238+ , D.toSimpleNote
1239+ "I count the length in bytes, so using non-ASCII characters costs extra.\
1240+ \ Please report your case at https://github.com/elm/compiler/issues if this seems\
1241+ \ overly restrictive for your needs."
1242+ ]
1243+ )
1244+
1245+ OP_NoSrcDirs ->
1246+ toSnippet "NO SOURCE DIRECTORIES" Nothing
1247+ ( D.reflow $
1248+ "I got stuck while reading your elm.json file. You do not have any \"source-directories\" listed here:"
1249+ , D.fillSep
1250+ ["I","need","something","like",D.green "[\"src\"]"
1251+ ,"so","I","know","where","to","look","for","your","modules!"
1252+ ]
1253+ )
1254+
1255+
1256+
1257+-- DETAILS
1258+
1259+
1260+data Details
1261+ = DetailsNoSolution
1262+ | DetailsNoOfflineSolution
1263+ | DetailsSolverProblem Solver
1264+ | DetailsBadElmInPkg C.Constraint
1265+ | DetailsBadElmInAppOutline V.Version
1266+ | DetailsHandEditedDependencies
1267+ | DetailsBadOutline Outline
1268+ | DetailsCannotGetRegistry RegistryProblem
1269+ | DetailsBadDeps FilePath [DetailsBadDep]
1270+
1271+
1272+data DetailsBadDep
1273+ = BD_BadDownload Pkg.Name V.Version PackageProblem
1274+ | BD_BadBuild Pkg.Name V.Version (Map.Map Pkg.Name V.Version)
1275+
1276+
1277+toDetailsReport :: Details -> Help.Report
1278+toDetailsReport details =
1279+ case details of
1280+ DetailsNoSolution ->
1281+ Help.report "INCOMPATIBLE DEPENDENCIES" (Just "elm.json")
1282+ "The dependencies in your elm.json are not compatible."
1283+ [ D.fillSep
1284+ ["Did","you","change","them","by","hand?","Try","to","change","it","back!"
1285+ ,"It","is","much","more","reliable","to","add","dependencies","with",D.green "elm install" <> "."
1286+ ]
1287+ , D.reflow $
1288+ "Please ask for help on the community forums if you try those paths and are still\
1289+ \ having problems!"
1290+ ]
1291+
1292+ DetailsNoOfflineSolution ->
1293+ Help.report "TROUBLE VERIFYING DEPENDENCIES" (Just "elm.json")
1294+ "I could not connect to https://package.elm-lang.org to get the latest list of\
1295+ \ packages, and I was unable to verify your dependencies with the information I\
1296+ \ have cached locally."
1297+ [ D.reflow $
1298+ "Are you able to connect to the internet? These dependencies may work once you\
1299+ \ get access to the registry!"
1300+ , D.toFancyNote
1301+ ["If","you","changed","your","dependencies","by","hand,","try","to","change","them","back!"
1302+ ,"It","is","much","more","reliable","to","add","dependencies","with",D.green "elm install" <> "."
1303+ ]
1304+ ]
1305+
1306+ DetailsSolverProblem solver ->
1307+ toSolverReport solver
1308+
1309+ DetailsBadElmInPkg constraint ->
1310+ Help.report "ELM VERSION MISMATCH" (Just "elm.json")
1311+ "Your elm.json says this package needs a version of Elm in this range:"
1312+ [ D.indent 4 $ D.dullyellow $ D.fromChars $ C.toChars constraint
1313+ , D.fillSep
1314+ [ "But", "you", "are", "using", "Elm"
1315+ , D.red (D.fromVersion V.compiler)
1316+ , "right", "now."
1317+ ]
1318+ ]
1319+
1320+ DetailsBadElmInAppOutline version ->
1321+ Help.report "ELM VERSION MISMATCH" (Just "elm.json")
1322+ "Your elm.json says this application needs a different version of Elm."
1323+ [ D.fillSep
1324+ [ "It", "requires"
1325+ , D.green (D.fromVersion version) <> ","
1326+ , "but", "you", "are", "using"
1327+ , D.red (D.fromVersion V.compiler)
1328+ , "right", "now."
1329+ ]
1330+ ]
1331+
1332+ DetailsHandEditedDependencies ->
1333+ Help.report "ERROR IN DEPENDENCIES" (Just "elm.json")
1334+ "It looks like the dependencies elm.json in were edited by hand (or by a 3rd\
1335+ \ party tool) leaving them in an invalid state."
1336+ [ D.fillSep
1337+ ["Try","to","change","them","back","to","what","they","were","before!"
1338+ ,"It","is","much","more","reliable","to","add","dependencies","with",D.green "elm install" <> "."
1339+ ]
1340+ , D.reflow $
1341+ "Please ask for help on the community forums if you try those paths and are still\
1342+ \ having problems!"
1343+ ]
1344+
1345+ DetailsBadOutline outline ->
1346+ toOutlineReport outline
1347+
1348+ DetailsCannotGetRegistry problem ->
1349+ toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
1350+ "I need the list of published packages to verify your dependencies"
1351+
1352+ DetailsBadDeps cacheDir deps ->
1353+ case List.sortOn toBadDepRank deps of
1354+ [] ->
1355+ Help.report "PROBLEM BUILDING DEPENDENCIES" Nothing
1356+ "I am not sure what is going wrong though."
1357+ [ D.reflow $
1358+ "I would try deleting the " ++ cacheDir ++ " and elm-stuff/ directories, then\
1359+ \ trying to build again. That will work if some cached files got corrupted\
1360+ \ somehow."
1361+ , D.reflow $
1362+ "If that does not work, go to https://elm-lang.org/community and ask for\
1363+ \ help. This is a weird case!"
1364+ ]
1365+
1366+ d:_ ->
1367+ case d of
1368+ BD_BadDownload pkg vsn packageProblem ->
1369+ toPackageProblemReport pkg vsn packageProblem
1370+
1371+ BD_BadBuild pkg vsn fingerprint ->
1372+ Help.report "PROBLEM BUILDING DEPENDENCIES" Nothing
1373+ "I ran into a compilation error when trying to build the following package:"
1374+ [ D.indent 4 $ D.red $ D.fromChars $ Pkg.toChars pkg ++ " " ++ V.toChars vsn
1375+ , D.reflow $
1376+ "This probably means it has package constraints that are too wide. It may be\
1377+ \ possible to tweak your elm.json to avoid the root problem as a stopgap. Head\
1378+ \ over to https://elm-lang.org/community to get help figuring out how to take\
1379+ \ this path!"
1380+ , D.toSimpleNote $
1381+ "To help with the root problem, please report this to the package author along\
1382+ \ with the following information:"
1383+ , D.indent 4 $ D.vcat $
1384+ map (\(p,v) -> D.fromChars $ Pkg.toChars p ++ " " ++ V.toChars v) $
1385+ Map.toList fingerprint
1386+ , D.reflow $
1387+ "If you want to help out even more, try building the package locally. That should\
1388+ \ give you much more specific information about why this package is failing to\
1389+ \ build, which will in turn make it easier for the package author to fix it!"
1390+ ]
1391+
1392+
1393+toBadDepRank :: DetailsBadDep -> Int -- lower is better
1394+toBadDepRank badDep =
1395+ case badDep of
1396+ BD_BadDownload _ _ _ -> 0
1397+ BD_BadBuild _ _ _ -> 1
1398+
1399+
1400+
1401+-- PACKAGE PROBLEM
1402+
1403+
1404+data PackageProblem
1405+ = PP_BadEndpointRequest Http.Error
1406+ | PP_BadEndpointContent String
1407+ | PP_BadArchiveRequest Http.Error
1408+ | PP_BadArchiveContent String
1409+ | PP_BadArchiveHash String String String
1410+
1411+
1412+toPackageProblemReport :: Pkg.Name -> V.Version -> PackageProblem -> Help.Report
1413+toPackageProblemReport pkg vsn problem =
1414+ let
1415+ thePackage =
1416+ Pkg.toChars pkg ++ " " ++ V.toChars vsn
1417+ in
1418+ case problem of
1419+ PP_BadEndpointRequest httpError ->
1420+ toHttpErrorReport "PROBLEM DOWNLOADING PACKAGE" httpError $
1421+ "I need to find the latest download link for " ++ thePackage
1422+
1423+ PP_BadEndpointContent url ->
1424+ Help.report "PROBLEM DOWNLOADING PACKAGE" Nothing
1425+ (
1426+ "I need to find the latest download link for " ++ thePackage ++ ", but I ran into corrupted information from:"
1427+ )
1428+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
1429+ , D.reflow $
1430+ "Is something weird with your internet connection. We have gotten reports that\
1431+ \ schools, businesses, airports, etc. sometimes intercept requests and add things\
1432+ \ to the body or change its contents entirely. Could that be the problem?"
1433+ ]
1434+
1435+ PP_BadArchiveRequest httpError ->
1436+ toHttpErrorReport "PROBLEM DOWNLOADING PACKAGE" httpError $
1437+ "I was trying to download the source code for " ++ thePackage
1438+
1439+ PP_BadArchiveContent url ->
1440+ Help.report "PROBLEM DOWNLOADING PACKAGE" Nothing
1441+ (
1442+ "I downloaded the source code for " ++ thePackage ++ " from:"
1443+ )
1444+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
1445+ , D.reflow $
1446+ "But I was unable to unzip the data. Maybe there is something weird with\
1447+ \ your internet connection. We have gotten reports that schools, businesses,\
1448+ \ airports, etc. sometimes intercept requests and add things to the body or\
1449+ \ change its contents entirely. Could that be the problem?"
1450+ ]
1451+
1452+ PP_BadArchiveHash url expectedHash actualHash ->
1453+ Help.report "CORRUPT PACKAGE DATA" Nothing
1454+ (
1455+ "I downloaded the source code for " ++ thePackage ++ " from:"
1456+ )
1457+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
1458+ , D.reflow "But it looks like the hash of the archive has changed since publication:"
1459+ , D.vcat $ map D.fromChars $
1460+ [ " Expected: " ++ expectedHash
1461+ , " Actual: " ++ actualHash
1462+ ]
1463+ , D.reflow $
1464+ "This usually means that the package author moved the version\
1465+ \ tag, so report it to them and see if that is the issue. Folks\
1466+ \ on Elm slack can probably help as well."
1467+ ]
1468+
1469+
1470+
1471+-- REGISTRY PROBLEM
1472+
1473+
1474+data RegistryProblem
1475+ = RP_Http Http.Error
1476+ | RP_Data String BS.ByteString
1477+
1478+
1479+toRegistryProblemReport :: String -> RegistryProblem -> String -> Help.Report
1480+toRegistryProblemReport title problem context =
1481+ case problem of
1482+ RP_Http err ->
1483+ toHttpErrorReport title err context
1484+
1485+ RP_Data url body ->
1486+ Help.report title Nothing (context ++ ", so I fetched:")
1487+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
1488+ , D.reflow $
1489+ "I got the data back, but it was not what I was expecting. The response\
1490+ \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
1491+ ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
1492+ , D.indent 4 $ D.dullyellow $ D.fromChars $
1493+ if BS.length body <= 76
1494+ then BS_UTF8.toString body
1495+ else take 73 (BS_UTF8.toString body) ++ "..."
1496+ , D.reflow $
1497+ "Does this error keep showing up? Maybe there is something weird with your\
1498+ \ internet connection. We have gotten reports that schools, businesses,\
1499+ \ airports, etc. sometimes intercept requests and add things to the body\
1500+ \ or change its contents entirely. Could that be the problem?"
1501+ ]
1502+
1503+
1504+toHttpErrorReport :: String -> Http.Error -> String -> Help.Report
1505+toHttpErrorReport title err context =
1506+ let
1507+ toHttpReport intro url details =
1508+ Help.report title Nothing intro $
1509+ D.indent 4 (D.dullyellow (D.fromChars url)) : details
1510+ in
1511+ case err of
1512+ Http.BadUrl url reason ->
1513+ toHttpReport (context ++ ", so I wanted to fetch:") url
1514+ [ D.reflow $ "But my HTTP library is saying this is not a valid URL. It is saying:"
1515+ , D.indent 4 $ D.fromChars reason
1516+ , D.reflow $
1517+ "This may indicate that there is some problem in the compiler, so please open an\
1518+ \ issue at https://github.com/elm/compiler/issues listing your operating system, Elm\
1519+ \ version, the command you ran, the terminal output, and any additional information\
1520+ \ that might help others reproduce the error."
1521+ ]
1522+
1523+ Http.BadHttp url httpExceptionContent ->
1524+ case httpExceptionContent of
1525+ HTTP.StatusCodeException response body ->
1526+ let
8051527 (HTTP.Status code message) = HTTP.responseStatus response
8061528 in
8071529 toHttpReport (context ++ ", so I tried to fetch:") url
8081530 [ D.fillSep $
8091531 ["But","it","came","back","as",D.red (D.fromInt code)]
8101532 ++ map D.fromChars (words (BS_UTF8.toString message))
1533+ , D.indent 4 $ D.reflow $ BS_UTF8.toString body
8111534 , D.reflow $
8121535 "This may mean some online endpoint changed in an unexpected way, so if does not\
8131536 \ seem like something on your side is causing this (e.g. firewall) please report\
@@ -863,155 +1586,380 @@ toRedirectDoc response =
8631586
8641587
8651588data Make
866− = MakeNeedsOutline
1589+ = MakeNoOutline
8671590 | MakeCannotOptimizeAndDebug
868− | MakeBlockedByDetailsProblem Details
1591+ | MakeBadDetails Details
8691592 | MakeAppNeedsFileNames
8701593 | MakePkgNeedsExposing
8711594 | MakeMultipleFilesIntoHtml
1595+ | MakeNoMain
8721596 | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
873− | MakeCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
8741597 | MakeCannotBuild BuildProblem
875− | MakeCannotLoadArtifacts
1598+ | MakeBadGenerate Generate
1599+
1600+
1601+makeToReport :: Make -> Help.Report
1602+makeToReport make =
1603+ case make of
1604+ MakeNoOutline ->
1605+ Help.report "NO elm.json FILE" Nothing
1606+ "It looks like you are starting a new Elm project. Very exciting! Try running:"
1607+ [ D.indent 4 $ D.green $ "elm init"
1608+ , D.reflow $
1609+ "It will help you get set up. It is really simple!"
1610+ ]
1611+
1612+ MakeCannotOptimizeAndDebug ->
1613+ Help.docReport "CLASHING FLAGS" Nothing
1614+ ( D.fillSep
1615+ ["I","cannot","compile","with",D.red "--optimize","and"
1616+ ,D.red "--debug","at","the","same","time."
1617+ ]
1618+ )
1619+ [ D.reflow
1620+ "I need to take away information to optimize things, and I need to\
1621+ \ add information to add the debugger. It is impossible to do both\
1622+ \ at once though! Pick just one of those flags and it should work!"
1623+ ]
1624+
1625+ MakeBadDetails detailsProblem ->
1626+ toDetailsReport detailsProblem
1627+
1628+ MakeAppNeedsFileNames ->
1629+ Help.report "NO INPUT" Nothing
1630+ "What should I make though? I need specific files like:"
1631+ [ D.vcat
1632+ [ D.indent 4 $ D.green "elm make src/Main.elm"
1633+ , D.indent 4 $ D.green "elm make src/This.elm src/That.elm"
1634+ ]
1635+ , D.reflow $
1636+ "I recommend reading through https://guide.elm-lang.org for guidance on what to\
1637+ \ actually put in those files!"
1638+ ]
1639+
1640+ MakePkgNeedsExposing ->
1641+ Help.report "NO INPUT" Nothing
1642+ "What should I make though? I need specific files like:"
1643+ [ D.vcat
1644+ [ D.indent 4 $ D.green "elm make src/Main.elm"
1645+ , D.indent 4 $ D.green "elm make src/This.elm src/That.elm"
1646+ ]
1647+ , D.reflow $
1648+ "You can also entries to the \"exposed-modules\" list in your elm.json file, and\
1649+ \ I will try to compile the relevant files."
1650+ ]
1651+
1652+ MakeMultipleFilesIntoHtml ->
1653+ Help.report "TOO MANY FILES" Nothing
1654+ (
1655+ "When producing an HTML file, I can only handle one file."
1656+ )
1657+ [ D.fillSep
1658+ ["Switch","to",D.dullyellow "--output=/dev/null","if","you","just","want"
1659+ ,"to","get","compile","errors.","This","skips","the","code","gen","phase,"
1660+ ,"so","it","can","be","a","bit","faster","than","other","options","sometimes."
1661+ ]
1662+ , D.fillSep
1663+ ["Switch","to",D.dullyellow "--output=elm.js","if","you","want","multiple"
1664+ ,"`main`","values","available","in","a","single","JavaScript","file.","Then"
1665+ ,"you","can","make","your","own","customized","HTML","file","that","embeds"
1666+ ,"multiple","Elm","nodes.","The","generated","JavaScript","also","shares"
1667+ ,"dependencies","between","modules,","so","it","should","be","smaller","than"
1668+ ,"compiling","each","module","separately."
1669+ ]
1670+ ]
1671+
1672+ MakeNoMain ->
1673+ Help.report "NO MAIN" Nothing
1674+ (
1675+ "When producing an HTML file, I require that the given file has a `main` value.\
1676+ \ That way I have something to show on screen!"
1677+ )
1678+ [ D.reflow $
1679+ "Try adding a `main` value to your file? Or if you just want to verify that this\
1680+ \ module compiles, switch to --output=/dev/null to skip the code gen phase\
1681+ \ altogether."
1682+ , D.toSimpleNote $
1683+ "Adding a `main` value can be as brief as adding something like this:"
1684+ , D.vcat
1685+ [ D.fillSep [D.cyan "import","Html"]
1686+ , ""
1687+ , D.fillSep [D.green "main","="]
1688+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1689+ ]
1690+ , D.reflow $
1691+ "From there I can create an HTML file that says \"Hello!\" on screen. I recommend\
1692+ \ looking through https://guide.elm-lang.org for more guidance on how to fill in\
1693+ \ the `main` value."
1694+ ]
1695+
1696+ MakeNonMainFilesIntoJavaScript m ms ->
1697+ case ms of
1698+ [] ->
1699+ Help.report "NO MAIN" Nothing
1700+ (
1701+ "When producing a JS file, I require that the given file has a `main` value. That\
1702+ \ way Elm." ++ ModuleName.toChars m ++ ".init() is definitely defined in the\
1703+ \ resulting file!"
1704+ )
1705+ [ D.reflow $
1706+ "Try adding a `main` value to your file? Or if you just want to verify that this\
1707+ \ module compiles, switch to --output=/dev/null to skip the code gen phase\
1708+ \ altogether."
1709+ , D.toSimpleNote $
1710+ "Adding a `main` value can be as brief as adding something like this:"
1711+ , D.vcat
1712+ [ D.fillSep [D.cyan "import","Html"]
1713+ , ""
1714+ , D.fillSep [D.green "main","="]
1715+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1716+ ]
1717+ , D.reflow $
1718+ "Or use https://package.elm-lang.org/packages/elm/core/latest/Platform#worker to\
1719+ \ make a `main` with no user interface."
1720+ ]
1721+
1722+ _:_ ->
1723+ Help.report "NO MAIN" Nothing
1724+ (
1725+ "When producing a JS file, I require that given files all have `main` values.\
1726+ \ That way functions like Elm." ++ ModuleName.toChars m ++ ".init() are\
1727+ \ definitely defined in the resulting file. I am missing `main` values in:"
1728+ )
1729+ [ D.indent 4 $ D.red $ D.vcat $ map D.fromName (m:ms)
1730+ , D.reflow $
1731+ "Try adding a `main` value to them? Or if you just want to verify that these\
1732+ \ modules compile, switch to --output=/dev/null to skip the code gen phase\
1733+ \ altogether."
1734+ , D.toSimpleNote $
1735+ "Adding a `main` value can be as brief as adding something like this:"
1736+ , D.vcat
1737+ [ D.fillSep [D.cyan "import","Html"]
1738+ , ""
1739+ , D.fillSep [D.green "main","="]
1740+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1741+ ]
1742+ , D.reflow $
1743+ "Or use https://package.elm-lang.org/packages/elm/core/latest/Platform#worker to\
1744+ \ make a `main` with no user interface."
1745+ ]
1746+
1747+ MakeCannotBuild buildProblem ->
1748+ toBuildProblemReport buildProblem
1749+
1750+ MakeBadGenerate generateProblem ->
1751+ toGenerateReport generateProblem
1752+
1753+
1754+
1755+-- BUILD PROBLEM
8761756
8771757
8781758data BuildProblem
879− = BuildModuleProblems Error.Module [Error.Module]
1759+ = BuildBadModules FilePath Error.Module [Error.Module]
8801760 | BuildProjectProblem BuildProjectProblem
8811761
8821762
8831763data BuildProjectProblem
8841764 = BP_PathUnknown FilePath
8851765 | BP_WithBadExtension FilePath
886− | BP_WithAmbiguousSrcDir FilePath FilePath
1766+ | BP_WithAmbiguousSrcDir FilePath FilePath FilePath
8871767 | BP_MainPathDuplicate FilePath FilePath
888− | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
1768+ | BP_RootNameDuplicate ModuleName.Raw FilePath FilePath
1769+ | BP_RootNameInvalid FilePath FilePath [String]
8891770 | BP_CannotLoadDependencies
8901771 | BP_Cycle ModuleName.Raw [ModuleName.Raw]
8911772 | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
8921773
8931774
1775+toBuildProblemReport :: BuildProblem -> Help.Report
1776+toBuildProblemReport problem =
1777+ case problem of
1778+ BuildBadModules root e es ->
1779+ Help.compilerReport root e es
8941780
895−-- RENDERERS
896−
897−
898−toString :: Help.Report -> String
899−toString report =
900− Help.toString (Help.reportToDoc report)
1781+ BuildProjectProblem projectProblem ->
1782+ toProjectProblemReport projectProblem
9011783
9021784
903−toStderr :: Help.Report -> IO ()
904−toStderr report =
905− Help.toStderr (Help.reportToDoc report)
1785+toProjectProblemReport :: BuildProjectProblem -> Help.Report
1786+toProjectProblemReport projectProblem =
1787+ case projectProblem of
1788+ BP_PathUnknown path ->
1789+ Help.report "FILE NOT FOUND" Nothing
1790+ "I cannot find this file:"
1791+ [ D.indent 4 $ D.red $ D.fromChars path
1792+ , D.reflow $ "Is there a typo?"
1793+ , D.toSimpleNote $
1794+ "If you are just getting started, try working through the examples in the\
1795+ \ official guide https://guide.elm-lang.org to get an idea of the kinds of things\
1796+ \ that typically go in a src/Main.elm file."
1797+ ]
9061798
1799+ BP_WithBadExtension path ->
1800+ Help.report "UNEXPECTED FILE EXTENSION" Nothing
1801+ "I can only compile Elm files (with a .elm extension) but you want me to compile:"
1802+ [ D.indent 4 $ D.red $ D.fromChars path
1803+ , D.reflow $ "Is there a typo? Can the file extension be changed?"
1804+ ]
9071805
908−toJson :: Help.Report -> Encode.Value
909−toJson report =
910− Help.reportToJson report
1806+ BP_WithAmbiguousSrcDir path srcDir1 srcDir2 ->
1807+ Help.report "CONFUSING FILE" Nothing
1808+ "I am getting confused when I try to compile this file:"
1809+ [ D.indent 4 $ D.red $ D.fromChars path
1810+ , D.reflow $
1811+ "I always check if files appear in any of the \"source-directories\" listed in\
1812+ \ your elm.json to see if there might be some cached information about them. That\
1813+ \ can help me compile faster! But in this case, it looks like this file may be in\
1814+ \ either of these directories:"
1815+ , D.indent 4 $ D.red $ D.vcat $ map D.fromChars [srcDir1,srcDir2]
1816+ , D.reflow $
1817+ "Try to make it so no source directory contains another source directory!"
1818+ ]
9111819
1820+ BP_MainPathDuplicate path1 path2 ->
1821+ Help.report "CONFUSING FILES" Nothing
1822+ "You are telling me to compile these two files:"
1823+ [ D.indent 4 $ D.red $ D.vcat $ map D.fromChars [ path1, path2 ]
1824+ , D.reflow $
1825+ if path1 == path2 then
1826+ "Why are you telling me twice? Is something weird going on with a script?\
1827+ \ I figured I would let you know about it just in case something is wrong.\
1828+ \ Only list it once and you should be all set!"
1829+ else
1830+ "But seem to be the same file though... It makes me think something tricky is\
1831+ \ going on with symlinks in your project, so I figured I would let you know\
1832+ \ about it just in case. Remove one of these files from your command to get\
1833+ \ unstuck!"
1834+ ]
9121835
1836+ BP_RootNameDuplicate name outsidePath otherPath ->
1837+ Help.report "MODULE NAME CLASH" Nothing
1838+ "These two files are causing a module name clash:"
1839+ [ D.indent 4 $ D.red $ D.vcat $ map D.fromChars [ outsidePath, otherPath ]
1840+ , D.reflow $
1841+ "They both say `module " ++ ModuleName.toChars name ++ " exposing (..)` up\
1842+ \ at the top, but they cannot have the same name!"
1843+ , D.reflow $
1844+ "Try changing to a different module name in one of them!"
1845+ ]
9131846
914−-- DETAILS TO REPORT
1847+ BP_RootNameInvalid givenPath srcDir _ ->
1848+ Help.report "UNEXPECTED FILE NAME" Nothing
1849+ "I am having trouble with this file name:"
1850+ [ D.indent 4 $ D.red $ D.fromChars givenPath
1851+ , D.reflow $
1852+ "I found it in your " ++ FP.addTrailingPathSeparator srcDir ++ " directory\
1853+ \ which is good, but I expect all of the files in there to use the following\
1854+ \ module naming convention:"
1855+ , toModuleNameConventionTable srcDir [ "Main", "HomePage", "Http.Helpers" ]
1856+ , D.reflow $
1857+ "Notice that the names always start with capital letters! Can you make your file\
1858+ \ use this naming convention?"
1859+ , D.toSimpleNote $
1860+ "Having a strict naming convention like this makes it a lot easier to find\
1861+ \ things in large projects. If you see a module imported, you know where to look\
1862+ \ for the corresponding file every time!"
1863+ ]
9151864
1865+ BP_CannotLoadDependencies ->
1866+ corruptCacheReport
9161867
917−detailsToReport :: Details -> Help.Report
918−detailsToReport details =
919− case details of
920− DetailsCorrupt ->
921− error "TODO DetailsCorrupt"
922−
923− DetailsBadElmInPkg constraint ->
924− Help.report "ELM VERSION MISMATCH" (Just "elm.json")
925− "Your elm.json says this package needs a version of Elm in this range:"
926− [ D.indent 4 $ D.dullyellow $ D.fromChars $ C.toChars constraint
927− , D.fillSep
928− [ "But", "you", "are", "using", "Elm"
929− , D.red (D.fromVersion V.compiler)
930− , "right", "now."
931− ]
1868+ BP_Cycle name names ->
1869+ Help.report "IMPORT CYCLE" Nothing
1870+ "Your module imports form a cycle:"
1871+ [ D.cycle 4 name names
1872+ , D.reflow $
1873+ "Learn more about why this is disallowed and how to break cycles here:"
1874+ ++ D.makeLink "import-cycles"
9321875 ]
9331876
934− DetailsBadElmInAppOutline version ->
935− Help.report "ELM VERSION MISMATCH" (Just "elm.json")
936− "Your elm.json says this application needs a different version of Elm."
937− [ D.fillSep
938− [ "It", "requires"
939− , D.green (D.fromVersion version) <> ","
940− , "but", "you", "are", "using"
941− , D.red (D.fromVersion V.compiler)
942− , "right", "now."
1877+ BP_MissingExposed (NE.List (name, problem) _) ->
1878+ case problem of
1879+ Import.NotFound ->
1880+ Help.report "MISSING MODULE" (Just "elm.json")
1881+ "The \"exposed-modules\" of your elm.json lists the following module:"
1882+ [ D.indent 4 $ D.red $ D.fromName name
1883+ , D.reflow $
1884+ "But I cannot find it in your src/ directory. Is there a typo? Was it renamed?"
9431885 ]
944− ]
9451886
946− DetailsHandEditedDependencies ->
947− error "TODO DetailsHandEditedDependencies"
1887+ Import.Ambiguous _ _ pkg _ ->
1888+ Help.report "AMBIGUOUS MODULE NAME" (Just "elm.json")
1889+ "The \"exposed-modules\" of your elm.json lists the following module:"
1890+ [ D.indent 4 $ D.red $ D.fromName name
1891+ , D.reflow $
1892+ "But a module from " ++ Pkg.toChars pkg ++ " already uses that name. Try\
1893+ \ choosing a different name for your local file."
1894+ ]
9481895
949− DetailsBadOutline outline ->
950− toOutlineReport outline
1896+ Import.AmbiguousLocal path1 path2 paths ->
1897+ Help.report "AMBIGUOUS MODULE NAME" (Just "elm.json")
1898+ "The \"exposed-modules\" of your elm.json lists the following module:"
1899+ [ D.indent 4 $ D.red $ D.fromName name
1900+ , D.reflow $
1901+ "But I found multiple files with that name:"
1902+ , D.dullyellow $ D.indent 4 $ D.vcat $
1903+ map D.fromChars (path1:path2:paths)
1904+ , D.reflow $
1905+ "Change the module names to be distinct!"
1906+ ]
9511907
952− 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"
1908+ Import.AmbiguousForeign _ _ _ ->
1909+ Help.report "MISSING MODULE" (Just "elm.json")
1910+ "The \"exposed-modules\" of your elm.json lists the following module:"
1911+ [ D.indent 4 $ D.red $ D.fromName name
1912+ , D.reflow $
1913+ "But I cannot find it in your src/ directory. Is there a typo? Was it renamed?"
1914+ , D.toSimpleNote $
1915+ "It is not possible to \"re-export\" modules from other packages. You can only\
1916+ \ expose modules that you define in your own code."
1917+ ]
9551918
956− DetailsCannotBuildPackage name version problem ->
957− error "TODO DetailsCannotBuildPackage" name version problem
9581919
959− DetailsNoSolution ->
960− error "TODO DetailsNoSolution"
1920+toModuleNameConventionTable :: FilePath -> [String] -> D.Doc
1921+toModuleNameConventionTable srcDir names =
1922+ let
1923+ toPair name =
1924+ ( name
1925+ , srcDir </> map (\c -> if c == '.' then FP.pathSeparator else c) name <.> "elm"
1926+ )
9611927
962− DetailsNoOfflineSolution ->
963− error "TODO DetailsNoOfflineSolution"
1928+ namePairs = map toPair names
1929+ nameWidth = maximum (11 : map (length . fst) namePairs)
1930+ pathWidth = maximum ( 9 : map (length . snd) namePairs)
9641931
965− DetailsSolverProblem _ ->
966− error "TODO DetailsSolverProblem"
1932+ padded width str =
1933+ str ++ replicate (width - length str) ' '
9671934
1935+ toRow (name, path) =
1936+ D.fromChars $
1937+ "| " ++ padded nameWidth name ++ " | " ++ padded pathWidth path ++ " |"
9681938
1939+ bar =
1940+ D.fromChars $
1941+ "+-" ++ replicate nameWidth '-' ++ "-+-" ++ replicate pathWidth '-' ++ "-+"
1942+ in
1943+ D.indent 4 $ D.vcat $
1944+ [ bar, toRow ("Module Name", "File Path"), bar ] ++ map toRow namePairs ++ [ bar ]
9691945
970−makeToReport :: Make -> Help.Report
971−makeToReport make =
972− case make of
973− MakeNeedsOutline ->
974− Help.report "NO elm.json FILE" Nothing
975− "It looks like you are starting a new Elm project. Very exciting! Try running:"
976− [ D.indent 4 $ D.green $ "elm init"
977− , D.reflow $
978− "It will help you get set up. It is really simple!"
979− ]
9801946
981− MakeCannotOptimizeAndDebug ->
982− Help.docReport "CLASHING FLAGS" Nothing
983− ( D.fillSep
984− ["I","cannot","compile","with",D.red "--optimize","and"
985− ,D.red "--debug","at","the","same","time."
986− ]
987− )
988− [ D.reflow
989− "I need to take away information to optimize things, and I need to\
990− \ add information to add the debugger. It is impossible to do both\
991− \ at once though! Pick just one of those flags and it should work!"
992− ]
9931947
994− MakeBlockedByDetailsProblem detailsProblem ->
995− detailsToReport detailsProblem
1948+-- GENERATE
9961949
997− MakeAppNeedsFileNames ->
998− Help.report "NO INPUT" Nothing
999− "What should I make though? I need a specific file like this:"
1000− [ D.indent 4 $ D.green "elm make src/Main.elm"
1001− , D.reflow
1002− "However many files you give, I will create one JS file out of them."
1003− ]
10041950
1005− MakePkgNeedsExposing ->
1006− error "TODO MakePkgNeedsExposing"
1951+data Generate
1952+ = GenerateCannotLoadArtifacts
1953+ | GenerateCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
10071954
1008− MakeMultipleFilesIntoHtml ->
1009− error "TODO MakeMultipleFilesIntoHtml"
10101955
1011− MakeNonMainFilesIntoJavaScript _ _ ->
1012− error "TODO MakeNonMainFilesIntoJavaScript"
1956+toGenerateReport :: Generate -> Help.Report
1957+toGenerateReport problem =
1958+ case problem of
1959+ GenerateCannotLoadArtifacts ->
1960+ corruptCacheReport
10131961
1014− MakeCannotOptimizeDebugValues m ms ->
1962+ GenerateCannotOptimizeDebugValues m ms ->
10151963 Help.report "DEBUG REMNANTS" Nothing
10161964 "There are uses of the `Debug` module in the following modules:"
10171965 [ D.indent 4 $ D.red $ D.vcat $ map (D.fromChars . ModuleName.toChars) (m:ms)
@@ -1020,7 +1968,7 @@ makeToReport make =
10201968 "The issue is that --optimize strips out info needed by `Debug` functions.\
10211969 \ Here are two examples:"
10221970 , D.indent 4 $ D.reflow $
1023− "(1) It shortens record field names. This makes the generated JavaScript is\
1971+ "(1) It shortens record field names. This makes the generated JavaScript\
10241972 \ smaller, but `Debug.toString` cannot know the real field names anymore."
10251973 , D.indent 4 $ D.reflow $
10261974 "(2) Values like `type Height = Height Float` are unboxed. This reduces\
@@ -1033,289 +1981,89 @@ makeToReport make =
10331981 \ exists!"
10341982 ]
10351983
1036− MakeCannotBuild buildProblem ->
1037− case buildProblem of
1038− BuildProjectProblem bp ->
1039− case bp of
1040− BP_PathUnknown _ ->
1041− error "TODO BP_PathUnknown"
1042−
1043− BP_WithBadExtension _ ->
1044− error "TODO BP_WithBadExtension"
1045−
1046− BP_WithAmbiguousSrcDir _ _ ->
1047− error "TODO BP_WithAmbiguousSrcDir"
10481984
1049− BP_MainPathDuplicate _ _ ->
1050− error "TODO BP_MainPathDuplicate"
10511985
1052− BP_MainNameDuplicate _ _ _ ->
1053− error "TODO BP_MainNameDuplicate"
1986+-- CORRUPT CACHE
10541987
1055− BP_CannotLoadDependencies ->
1056− error "TODO BP_CannotLoadDependencies"
10571988
1058− BP_Cycle name names ->
1059− Help.report "IMPORT CYCLE" Nothing
1060− "Your module imports form a cycle:"
1061− [ D.cycle 4 name names
1062− , D.reflow $
1063− "Learn more about why this is disallowed and how to break cycles here:"
1064− ++ D.makeLink "import-cycles"
1065− ]
1066−
1067− BP_MissingExposed _ ->
1068− error "TODO BP_MissingExposed"
1989+corruptCacheReport :: Help.Report
1990+corruptCacheReport =
1991+ Help.report "CORRUPT CACHE" Nothing
1992+ "It looks like some of the information cached in elm-stuff/ has been corrupted."
1993+ [ D.reflow $
1994+ "Try deleting your elm-stuff/ directory to get unstuck."
1995+ , D.toSimpleNote $
1996+ "This almost certainly means that a 3rd party tool (or editor plugin) is\
1997+ \ causing problems your the elm-stuff/ directory. Try disabling 3rd party tools\
1998+ \ one by one until you figure out which it is!"
1999+ ]
10692000
1070− BuildModuleProblems p ps ->
1071− Help.compilerReport p ps
10722001
1073− MakeCannotLoadArtifacts ->
1074− error "TODO MakeCannotLoadArtifacts"
10752002
2003+-- REACTOR
10762004
10772005
1078−-- OUTLINE
2006+data Reactor
2007+ = ReactorNoOutline
2008+ | ReactorBadDetails Details
2009+ | ReactorBadBuild BuildProblem
2010+ | ReactorBadGenerate Generate
10792011
10802012
1081−toOutlineReport :: Outline -> Help.Report
1082−toOutlineReport problem =
2013+reactorToReport :: Reactor -> Help.Report
2014+reactorToReport problem =
10832015 case problem of
1084− OutlineHasBadStructure decodeError ->
1085− Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError $
1086− Json.ExplicitReason "I ran into a problem with your elm.json file."
1087−
1088− OutlineHasBadSrcDirs dir dirs ->
1089− case dirs of
1090− [] ->
1091− Help.report "MISSING SOURCE DIRECTORY" (Just "elm.json")
1092− "I need a valid elm.json file, but the \"source-directories\" field lists the following directory:"
1093− [ D.indent 4 $ D.dullyellow $ D.fromChars dir
1094− , D.reflow $
1095− "I cannot find it though. Is it missing? Is there a typo?"
1096− ]
1097−
1098− _:_ ->
1099− Help.report "MISSING SOURCE DIRECTORIES" (Just "elm.json")
1100− "I need a valid elm.json file, but the \"source-directories\" field lists the following directories:"
1101− [ D.indent 4 $ D.dullyellow $ D.fromChars dir
1102− , D.reflow $
1103− "I cannot find them though. Are they missing? Are there typos?"
1104− ]
1105−
1106− OutlineNoPkgCore ->
1107− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1108− "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
1109− [ D.indent 4 $ D.green $ "elm install elm/core"
1110− , D.reflow "I need it for the default imports that make `List` and `Maybe` available."
2016+ ReactorNoOutline ->
2017+ Help.report "NEW PROJECT?" Nothing
2018+ "Are you trying to start a new project? Try this command in the terminal:"
2019+ [ D.indent 4 $ D.green "elm init"
2020+ , D.reflow "It will help you get started!"
11112021 ]
11122022
1113− OutlineNoAppCore ->
1114− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1115− "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
1116− [ D.indent 4 $ D.green $ "elm install elm/core"
1117− , D.reflow "It has some supporting code that is needed by every Elm application!"
1118− ]
2023+ ReactorBadDetails details ->
2024+ toDetailsReport details
11192025
1120− OutlineNoAppJson ->
1121− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1122− "I need a valid elm.json file, so I need to see an \"elm/json\" dependency in there. Try running:"
1123− [ D.indent 4 $ D.green $ "elm install elm/json"
1124− , D.reflow "It helps me handle flags and ports."
1125− ]
2026+ ReactorBadBuild buildProblem ->
2027+ toBuildProblemReport buildProblem
11262028
2029+ ReactorBadGenerate generate ->
2030+ toGenerateReport generate
11272031
1128−toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
1129−toOutlineProblemReport path source _ region problem =
1130− let
1131− toHighlight row col =
1132− Just $ A.Region (A.Position row col) (A.Position row col)
11332032
1134− toSnippet title highlight pair =
1135− Help.jsonReport title (Just path) $
1136− Code.toSnippet source region highlight pair
1137− in
1138− case problem of
1139− OP_BadType ->
1140− toSnippet "UNEXPECTED TYPE" Nothing
1141− ( D.reflow $
1142− "I got stuck while reading your elm.json file. I cannot handle a \"type\" like this:"
1143− , D.fillSep
1144− ["Try","changing","the","\"type\"","to"
1145− ,D.green "\"application\"","or",D.green "\"package\"","instead."
1146− ]
1147− )
11482033
1149− OP_BadPkgName row col ->
1150− toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
1151− ( D.reflow $
1152− "I got stuck while reading your elm.json file. I ran into trouble with the package name:"
1153− , D.stack
1154− [ D.fillSep
1155− ["Package","names","are","always","written","as"
1156− ,D.green "\"author/project\""
1157− ,"so","I","am","expecting","to","see","something","like:"
1158− ]
1159− , D.dullyellow $ D.indent 4 $ D.vcat $
1160− [ "\"mdgriffith/elm-ui\""
1161− , "\"w0rm/elm-physics\""
1162− , "\"Microsoft/elm-json-tree-view\""
1163− , "\"FordLabs/elm-star-rating\""
1164− , "\"1602/json-schema\""
1165− ]
1166− , D.reflow
1167− "The author name should match your GitHub name exactly, and the project name\
1168− \ needs to follow these rules:"
1169− , D.indent 4 $ D.vcat $
1170− [ "+--------------------------------------+-----------+-----------+"
1171− , "| RULE | BAD | GOOD |"
1172− , "+--------------------------------------+-----------+-----------+"
1173− , "| only lower case, digits, and hyphens | elm-HTTP | elm-http |"
1174− , "| no leading digits | 3D | elm-3d |"
1175− , "| no non-ASCII characters | elm-bjørn | elm-bear |"
1176− , "| no underscores | elm_ui | elm-ui |"
1177− , "| no double hyphens | elm--hash | elm-hash |"
1178− , "| no starting or ending hyphen | -elm-tar- | elm-tar |"
1179− , "+--------------------------------------+-----------+-----------+"
1180− ]
1181− , D.toSimpleNote $
1182− "These rules only apply to the project name, so you should never need\
1183− \ to change your GitHub name!"
1184− ]
1185− )
2034+-- REPL
11862035
1187− OP_BadVersion row col ->
1188− toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
1189− ( D.reflow $
1190− "I got stuck while reading your elm.json file. I was expecting a version number here:"
1191− , D.fillSep
1192− ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
1193− ,"that","explicitly","states","all","three","numbers!"
1194− ]
1195− )
11962036
1197− OP_BadConstraint constraintError ->
1198− case constraintError of
1199− C.BadFormat row col ->
1200− toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
1201− ( D.reflow $
1202− "I got stuck while reading your elm.json file. I do not understand this version constraint:"
1203− , D.stack
1204− [ D.fillSep
1205− ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
1206− ,"that","explicitly","lists","the","lower","and","upper","bounds."
1207− ]
1208− , D.toSimpleNote $
1209− "The spaces in there are required! Taking them out will confuse me. Adding\
1210− \ extra spaces confuses me too. I recommend starting with a valid example\
1211− \ and just changing the version numbers."
1212− ]
1213− )
2037+data Repl
2038+ = ReplBadDetails Details
2039+ | ReplBadInput BS.ByteString Error.Error
2040+ | ReplBadLocalDeps FilePath Error.Module [Error.Module]
2041+ | ReplProjectProblem BuildProjectProblem
2042+ | ReplBadGenerate Generate
2043+ | ReplBadCache
2044+ | ReplBlocked
12142045
1215− C.InvalidRange before after ->
1216− if before == after then
1217− toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1218− ( D.reflow $
1219− "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1220− , D.fillSep
1221− ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
1222− ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
1223− ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor after) <> "\""
1224− ,"since","it","is","guaranteed","that","breaking","API","changes","cannot"
1225− ,"happen","in","any","of","the","versions","in","that","range."
1226− ]
1227− )
12282046
1229− else
1230− toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1231− ( D.reflow $
1232− "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1233− , D.fillSep
1234− ["Maybe","you","want","something","like"
1235− ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
1236− ,"instead?","Elm","checks","that","all","package","APIs","follow","semantic"
1237− ,"versioning,","so","it","is","guaranteed","that","breaking","API","changes"
1238− ,"cannot","happen","in","any","of","the","versions","in","that","range."
1239− ]
1240− )
2047+replToReport :: Repl -> Help.Report
2048+replToReport problem =
2049+ case problem of
2050+ ReplBadDetails details ->
2051+ toDetailsReport details
12412052
1242− OP_BadModuleName row col ->
1243− toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
1244− ( D.reflow $
1245− "I got stuck while reading your elm.json file. I was expecting a module name here:"
1246− , D.fillSep
1247− ["I","need","something","like",D.green "\"Html.Events\""
1248− ,"or",D.green "\"Browser.Navigation\""
1249− ,"where","each","segment","starts","with","a","capital"
1250− ,"letter","and","the","segments","are","separated","by","dots."
1251− ]
1252− )
2053+ ReplBadInput source err ->
2054+ Help.compilerReport "/" (Error.Module N.replModule "REPL" File.zeroTime source err) []
12532055
1254− OP_BadModuleHeaderTooLong ->
1255− toSnippet "HEADER TOO LONG" Nothing
1256− ( D.reflow $
1257− "I got stuck while reading your elm.json file. This section header is too long:"
1258− , D.fillSep
1259− ["I","need","it","to","be"
1260− ,D.green "under",D.green "20",D.green "characters"
1261− ,"so","it","renders","nicely","on","the","package","website!"
1262− ]
1263− )
2056+ ReplBadLocalDeps root e es ->
2057+ Help.compilerReport root e es
12642058
1265− OP_BadDependencyName row col ->
1266− toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
1267− ( D.reflow $
1268− "I got stuck while reading your elm.json file. There is something wrong with this dependency name:"
1269− , D.stack
1270− [ D.fillSep
1271− ["Package","names","always","include","the","name","of","the","author,"
1272− ,"so","I","am","expecting","to","see","dependencies","like"
1273− ,D.dullyellow "\"mdgriffith/elm-ui\"","and"
1274− ,D.dullyellow "\"Microsoft/elm-json-tree-view\"" <> "."
1275− ]
1276− , D.fillSep $
1277− ["I","generally","recommend","finding","the","package","you","want","on"
1278− ,"the","package","website,","and","installing","it","with","the"
1279− ,D.green "elm install","command!"
1280− ]
1281− ]
1282− )
2059+ ReplProjectProblem projectProblem ->
2060+ toProjectProblemReport projectProblem
12832061
1284− OP_BadLicense _ suggestions ->
1285− toSnippet "UNKNOWN LICENSE" Nothing
1286− ( D.reflow $
1287− "I got stuck while reading your elm.json file. I do not know about this type of license:"
1288− ,
1289− D.stack
1290− [ D.fillSep
1291− ["Elm","packages","generally","use"
1292− ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\"" <> ","
1293− ,"but","I","accept","any","OSI","approved","SPDX","license."
1294− ,"Here","some","that","seem","close","to","what","you","wrote:"
1295− ]
1296− , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Json.toChars) suggestions
1297− , D.reflow $
1298− "Check out https://spdx.org/licenses/ for the full list of options."
1299− ]
1300− )
2062+ ReplBadGenerate generate ->
2063+ toGenerateReport generate
13012064
1302− OP_BadSummaryTooLong ->
1303− toSnippet "SUMMARY TOO LONG" Nothing
1304− ( D.reflow $
1305− "I got stuck while reading your elm.json file. Your \"summary\" is too long:"
1306− , D.fillSep
1307− ["I","need","it","to","be"
1308− ,D.green "under",D.green "80",D.green "characters"
1309− ,"so","it","renders","nicely","on","the","package","website!"
1310− ]
1311− )
2065+ ReplBadCache ->
2066+ corruptCacheReport
13122067
1313− OP_NoSrcDirs ->
1314− toSnippet "NO SOURCE DIRECTORIES" Nothing
1315− ( D.reflow $
1316− "I got stuck while reading your elm.json file. You do not have any \"source-directories\" listed here:"
1317− , D.fillSep
1318− ["I","need","something","like",D.green "[\"src\"]"
1319− ,"so","I","know","where","to","look","for","your","modules!"
1320− ]
1321− )
2068+ ReplBlocked ->
2069+ corruptCacheReport