on master help sign in
reorganize exits, add some entries for reactor and generator
commitbfda25426e8e7bad44af8aaa8ade99dd87fdf6e4 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 18 Jun 2019, 10:57 (7 years ago) parent3892770
1 file changed+618−511
builder/src/Reporting/Exit.hs+618−511
builder/src/Reporting/Exit.hs+618−511
@@ -1,37 +1,24 @@
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+ , Publish(..), publishToReport
8+ , Install(..), installToReport
9+ , Reactor(..), reactorToReport
1110 , newPackageOverview
1211 --
13− , Publish(..)
14− , publishToReport
15− --
16− , Install(..)
17− , installToReport
18− --
1912 , Solver(..)
20− --
2113 , Outline(..)
2214 , OutlineProblem(..)
23− --
2415 , Details(..)
2516 , PackageProblem(..)
26− --
2717 , RegistryProblem(..)
28− --
29− , Make(..)
3018 , BuildProblem(..)
3119 , BuildProjectProblem(..)
32− , makeToReport
33− --
3420 , DocsProblem(..)
21+ , Generate(..)
3522 --
3623 , toString
3724 , toStderr
@@ -69,6 +56,25 @@ import qualified Reporting.Render.Code as Code
6956
7057
7158
59+-- RENDERERS
60+
61+
62+toString :: Help.Report -> String
63+toString report =
64+ Help.toString (Help.reportToDoc report)
65+
66+
67+toStderr :: Help.Report -> IO ()
68+toStderr report =
69+ Help.toStderr (Help.reportToDoc report)
70+
71+
72+toJson :: Help.Report -> Encode.Value
73+toJson report =
74+ Help.reportToJson report
75+
76+
77+
7278-- INIT
7379
7480
@@ -96,10 +102,15 @@ initToReport exit =
96102
97103 InitNoOfflineSolution pkgs ->
98104 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
105+ "I tried to create an elm.json with the following direct dependencies:"
106+ [ D.indent 4 $ D.vcat $
107+ map (D.dullyellow . D.fromChars . Pkg.toChars) pkgs
108+ , D.reflow $
109+ "I could not find compatible versions though, but that may be because I could not\
110+ \ connect to https://package.elm-lang.org to get the latest list of packages. Are\
111+ \ you able to connect to the internet? Please ask around one of the community\
112+ \ forums at https://elm-lang.org/community for help!"
113+ ]
103114
104115 InitSolverProblem solver ->
105116 error "TODO InitSolverProblem" solver
@@ -159,11 +170,13 @@ diffToReport diff =
159170 , D.indent 4 $ D.dullyellow $ "elm diff elm/http 1.0.0 2.0.0"
160171 ]
161172
162− DiffNoExposed pkg ->
173+ DiffNoExposed _ ->
163174 Help.report "NO EXPOSED MODULES" (Just "elm.json")
164175 "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− []
176+ \ all right now! What am I supposed to diff?"
177+ [ D.reflow $
178+ "Try adding some modules back to the \"exposed-modules\" field."
179+ ]
167180
168181 DiffUnpublished ->
169182 Help.report "UNPUBLISHED" Nothing
@@ -320,7 +333,7 @@ data Publish
320333 | PublishCannotGetTag V.Version Http.Error
321334 | PublishCannotGetTagData V.Version String BS.ByteString
322335 | PublishCannotGetZip Http.Error
323− | PublishCannotDecodeZip
336+ | PublishCannotDecodeZip String
324337 | PublishCannotGetDocs V.Version V.Version DocsProblem
325338 | PublishCannotRegister Http.Error
326339 | PublishNoGit
@@ -544,10 +557,20 @@ publishToReport publish =
544557
545558 PublishCannotGetZip httpError ->
546559 toHttpErrorReport "PROBLEM DOWNLOADING CODE" httpError $
547− "I need to check that folks can download and build the source code when they install this package"
560+ "I need to check that folks can download and build the source code when they\
561+ \ install this package"
548562
549− PublishCannotDecodeZip ->
550− error "TODO PublishCannotDecodeZip"
563+ PublishCannotDecodeZip url ->
564+ Help.report "PROBLEM DOWNLOADING CODE" Nothing
565+ "I need to check that folks can download and build the source code when they\
566+ \ install this package, so I downloaded the code from:"
567+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
568+ , D.reflow $
569+ "I was unable to unzip the archive though. Maybe there is something weird with\
570+ \ your internet connection. We have gotten reports that schools, businesses,\
571+ \ airports, etc. sometimes intercept requests and add things to the body or\
572+ \ change its contents entirely. Could that be the problem?"
573+ ]
551574
552575 PublishCannotGetDocs old new docsProblem ->
553576 toDocsProblemReport docsProblem $
@@ -818,205 +841,276 @@ data OutlineProblem
818841 | OP_NoSrcDirs
819842
820843
821−
822−-- DETAILS
823−
824−
825−data Details
826− = DetailsCorrupt
827− | DetailsNoSolution
828− | DetailsNoOfflineSolution
829− | DetailsSolverProblem Solver
830− | DetailsBadElmInPkg C.Constraint
831− | DetailsBadElmInAppOutline V.Version
832− | DetailsHandEditedDependencies
833− | DetailsBadOutline Outline
834− | DetailsCannotGetRegistry RegistryProblem
835− | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
836−
837−
838−data PackageProblem
839− = PP_BadEndpointRequest Http.Error
840− | PP_BadEndpointContent
841− | PP_BadArchiveRequest Http.Error
842− | PP_BadArchiveContent
843− | PP_BadArchiveHash String String
844−
845−
846−
847−-- REGISTRY PROBLEM
848−
849−
850−data RegistryProblem
851− = RP_Http Http.Error
852− | RP_Data String BS.ByteString
853−
854−
855−toRegistryProblemReport :: String -> RegistryProblem -> String -> Help.Report
856−toRegistryProblemReport title problem context =
844+toOutlineReport :: Outline -> Help.Report
845+toOutlineReport problem =
857846 case problem of
858− RP_Http err ->
859− toHttpErrorReport title err context
860−
861− RP_Data url body ->
862− Help.report title Nothing (context ++ ", so I fetched:")
863− [ D.indent 4 $ D.dullyellow $ D.fromChars url
864− , D.reflow $
865− "I got the data back, but it was not what I was expecting. The response\
866− \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
867− ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
868− , D.indent 4 $ D.dullyellow $ D.fromChars $
869− if BS.length body <= 76
870− then BS_UTF8.toString body
871− else take 73 (BS_UTF8.toString body) ++ "..."
872− , D.reflow $
873− "Does this error keep showing up? Maybe there is something weird with your\
874− \ internet connection. We have gotten reports that schools, businesses,\
875− \ airports, etc. sometimes intercept requests and add things to the body\
876− \ or change its contents entirely. Could that be the problem?"
877− ]
878−
879−
880−toHttpErrorReport :: String -> Http.Error -> String -> Help.Report
881−toHttpErrorReport title err context =
882− let
883− toHttpReport intro url details =
884− Help.report title Nothing intro $
885− D.indent 4 (D.dullyellow (D.fromChars url)) : details
886− in
887− case err of
888− Http.BadUrl url reason ->
889− toHttpReport (context ++ ", so I wanted to fetch:") url
890− [ D.reflow $ "But my HTTP library is saying this is not a valid URL. It is saying:"
891− , D.indent 4 $ D.fromChars reason
892− , D.reflow $
893− "This may indicate that there is some problem in the compiler, so please open an\
894− \ issue at https://github.com/elm/compiler/issues listing your operating system, Elm\
895− \ version, the command you ran, the terminal output, and any additional information\
896− \ that might help others reproduce the error."
897− ]
898−
899− Http.BadHttp url httpExceptionContent ->
900− case httpExceptionContent of
901− HTTP.StatusCodeException response _ ->
902− let
903− (HTTP.Status code message) = HTTP.responseStatus response
904− in
905− toHttpReport (context ++ ", so I tried to fetch:") url
906− [ D.fillSep $
907− ["But","it","came","back","as",D.red (D.fromInt code)]
908− ++ map D.fromChars (words (BS_UTF8.toString message))
909− , D.reflow $
910− "This may mean some online endpoint changed in an unexpected way, so if does not\
911− \ seem like something on your side is causing this (e.g. firewall) please report\
912− \ this to https://github.com/elm/compiler/issues with your operating system, Elm\
913− \ version, the command you ran, the terminal output, and any additional information\
914− \ that can help others reproduce the error!"
915− ]
847+ OutlineHasBadStructure decodeError ->
848+ Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError $
849+ Json.ExplicitReason "I ran into a problem with your elm.json file."
916850
917− HTTP.TooManyRedirects responses ->
918− toHttpReport (context ++ ", so I tried to fetch:") url
919− [ D.reflow $ "But I gave up after following these " ++ show (length responses) ++ " redirects:"
920− , D.indent 4 $ D.vcat $ map toRedirectDoc responses
851+ OutlineHasBadSrcDirs dir dirs ->
852+ case dirs of
853+ [] ->
854+ Help.report "MISSING SOURCE DIRECTORY" (Just "elm.json")
855+ "I need a valid elm.json file, but the \"source-directories\" field lists the following directory:"
856+ [ D.indent 4 $ D.dullyellow $ D.fromChars dir
921857 , D.reflow $
922− "Is it possible that your internet connection intercepts certain requests? That\
923− \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
924− \ and certain countries. Try asking for help locally or in a community forum!"
858+ "I cannot find it though. Is it missing? Is there a typo?"
925859 ]
926860
927− otherException ->
928− toHttpReport (context ++ ", so I tried to fetch:") url
929− [ D.reflow $ "But my HTTP library is giving me the following error message:"
930− , D.indent 4 $ D.fromChars (show otherException)
861+ _:_ ->
862+ Help.report "MISSING SOURCE DIRECTORIES" (Just "elm.json")
863+ "I need a valid elm.json file, but the \"source-directories\" field lists the following directories:"
864+ [ D.indent 4 $ D.dullyellow $ D.fromChars dir
931865 , D.reflow $
932− "Are you somewhere with a slow internet connection? Or no internet?\
933− \ Does the link I am trying to fetch work in your browser? Maybe the\
934− \ site is down? Does your internet connection have a firewall that\
935− \ blocks certain domains? It is usually something like that!"
866+ "I cannot find them though. Are they missing? Are there typos?"
936867 ]
937868
938− Http.BadMystery url someException ->
939− toHttpReport (context ++ ", so I tried to fetch:") url
940− [ D.reflow $ "But I ran into something weird! I was able to extract this error message:"
941− , D.indent 4 $ D.fromChars (show someException)
942− , D.reflow $
943− "Is it possible that your internet connection intercepts certain requests? That\
944− \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
945− \ and certain countries. Try asking for help locally or in a community forum!"
869+ OutlineNoPkgCore ->
870+ Help.report "MISSING DEPENDENCY" (Just "elm.json")
871+ "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
872+ [ D.indent 4 $ D.green $ "elm install elm/core"
873+ , D.reflow "I need it for the default imports that make `List` and `Maybe` available."
946874 ]
947875
876+ OutlineNoAppCore ->
877+ Help.report "MISSING DEPENDENCY" (Just "elm.json")
878+ "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
879+ [ D.indent 4 $ D.green $ "elm install elm/core"
880+ , D.reflow "It has some supporting code that is needed by every Elm application!"
881+ ]
948882
949−toRedirectDoc :: HTTP.Response body -> D.Doc
950−toRedirectDoc response =
951− let
952− (HTTP.Status code message) = HTTP.responseStatus response
953− in
954− case List.lookup HTTP.hLocation (HTTP.responseHeaders response) of
955− Just loc -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString loc)
956− Nothing -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString message)
883+ OutlineNoAppJson ->
884+ Help.report "MISSING DEPENDENCY" (Just "elm.json")
885+ "I need a valid elm.json file, so I need to see an \"elm/json\" dependency in there. Try running:"
886+ [ D.indent 4 $ D.green $ "elm install elm/json"
887+ , D.reflow "It helps me handle flags and ports."
888+ ]
957889
958890
891+toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
892+toOutlineProblemReport path source _ region problem =
893+ let
894+ toHighlight row col =
895+ Just $ A.Region (A.Position row col) (A.Position row col)
959896
960−-- MAKE
897+ toSnippet title highlight pair =
898+ Help.jsonReport title (Just path) $
899+ Code.toSnippet source region highlight pair
900+ in
901+ case problem of
902+ OP_BadType ->
903+ toSnippet "UNEXPECTED TYPE" Nothing
904+ ( D.reflow $
905+ "I got stuck while reading your elm.json file. I cannot handle a \"type\" like this:"
906+ , D.fillSep
907+ ["Try","changing","the","\"type\"","to"
908+ ,D.green "\"application\"","or",D.green "\"package\"","instead."
909+ ]
910+ )
961911
912+ OP_BadPkgName row col ->
913+ toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
914+ ( D.reflow $
915+ "I got stuck while reading your elm.json file. I ran into trouble with the package name:"
916+ , D.stack
917+ [ D.fillSep
918+ ["Package","names","are","always","written","as"
919+ ,D.green "\"author/project\""
920+ ,"so","I","am","expecting","to","see","something","like:"
921+ ]
922+ , D.dullyellow $ D.indent 4 $ D.vcat $
923+ [ "\"mdgriffith/elm-ui\""
924+ , "\"w0rm/elm-physics\""
925+ , "\"Microsoft/elm-json-tree-view\""
926+ , "\"FordLabs/elm-star-rating\""
927+ , "\"1602/json-schema\""
928+ ]
929+ , D.reflow
930+ "The author name should match your GitHub name exactly, and the project name\
931+ \ needs to follow these rules:"
932+ , D.indent 4 $ D.vcat $
933+ [ "+--------------------------------------+-----------+-----------+"
934+ , "| RULE | BAD | GOOD |"
935+ , "+--------------------------------------+-----------+-----------+"
936+ , "| only lower case, digits, and hyphens | elm-HTTP | elm-http |"
937+ , "| no leading digits | 3D | elm-3d |"
938+ , "| no non-ASCII characters | elm-bjørn | elm-bear |"
939+ , "| no underscores | elm_ui | elm-ui |"
940+ , "| no double hyphens | elm--hash | elm-hash |"
941+ , "| no starting or ending hyphen | -elm-tar- | elm-tar |"
942+ , "+--------------------------------------+-----------+-----------+"
943+ ]
944+ , D.toSimpleNote $
945+ "These rules only apply to the project name, so you should never need\
946+ \ to change your GitHub name!"
947+ ]
948+ )
962949
963−data Make
964− = MakeNeedsOutline
965− | MakeCannotOptimizeAndDebug
966− | MakeBlockedByDetailsProblem Details
967− | MakeAppNeedsFileNames
968− | MakePkgNeedsExposing
969− | MakeMultipleFilesIntoHtml
970− | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
971− | MakeCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
972− | MakeCannotBuild BuildProblem
973− | MakeCannotLoadArtifacts
950+ OP_BadVersion row col ->
951+ toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
952+ ( D.reflow $
953+ "I got stuck while reading your elm.json file. I was expecting a version number here:"
954+ , D.fillSep
955+ ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
956+ ,"that","explicitly","states","all","three","numbers!"
957+ ]
958+ )
974959
960+ OP_BadConstraint constraintError ->
961+ case constraintError of
962+ C.BadFormat row col ->
963+ toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
964+ ( D.reflow $
965+ "I got stuck while reading your elm.json file. I do not understand this version constraint:"
966+ , D.stack
967+ [ D.fillSep
968+ ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
969+ ,"that","explicitly","lists","the","lower","and","upper","bounds."
970+ ]
971+ , D.toSimpleNote $
972+ "The spaces in there are required! Taking them out will confuse me. Adding\
973+ \ extra spaces confuses me too. I recommend starting with a valid example\
974+ \ and just changing the version numbers."
975+ ]
976+ )
975977
976−data BuildProblem
977− = BuildModuleProblems Error.Module [Error.Module]
978− | BuildProjectProblem BuildProjectProblem
978+ C.InvalidRange before after ->
979+ if before == after then
980+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
981+ ( D.reflow $
982+ "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
983+ , D.fillSep
984+ ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
985+ ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
986+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor after) <> "\""
987+ ,"since","it","is","guaranteed","that","breaking","API","changes","cannot"
988+ ,"happen","in","any","of","the","versions","in","that","range."
989+ ]
990+ )
979991
992+ else
993+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
994+ ( D.reflow $
995+ "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
996+ , D.fillSep
997+ ["Maybe","you","want","something","like"
998+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
999+ ,"instead?","Elm","checks","that","all","package","APIs","follow","semantic"
1000+ ,"versioning,","so","it","is","guaranteed","that","breaking","API","changes"
1001+ ,"cannot","happen","in","any","of","the","versions","in","that","range."
1002+ ]
1003+ )
9801004
981−data BuildProjectProblem
982− = BP_PathUnknown FilePath
983− | BP_WithBadExtension FilePath
984− | BP_WithAmbiguousSrcDir FilePath FilePath
985− | BP_MainPathDuplicate FilePath FilePath
986− | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
987− | BP_CannotLoadDependencies
988− | BP_Cycle ModuleName.Raw [ModuleName.Raw]
989− | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
1005+ OP_BadModuleName row col ->
1006+ toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
1007+ ( D.reflow $
1008+ "I got stuck while reading your elm.json file. I was expecting a module name here:"
1009+ , D.fillSep
1010+ ["I","need","something","like",D.green "\"Html.Events\""
1011+ ,"or",D.green "\"Browser.Navigation\""
1012+ ,"where","each","segment","starts","with","a","capital"
1013+ ,"letter","and","the","segments","are","separated","by","dots."
1014+ ]
1015+ )
9901016
1017+ OP_BadModuleHeaderTooLong ->
1018+ toSnippet "HEADER TOO LONG" Nothing
1019+ ( D.reflow $
1020+ "I got stuck while reading your elm.json file. This section header is too long:"
1021+ , D.fillSep
1022+ ["I","need","it","to","be"
1023+ ,D.green "under",D.green "20",D.green "characters"
1024+ ,"so","it","renders","nicely","on","the","package","website!"
1025+ ]
1026+ )
9911027
1028+ OP_BadDependencyName row col ->
1029+ toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
1030+ ( D.reflow $
1031+ "I got stuck while reading your elm.json file. There is something wrong with this dependency name:"
1032+ , D.stack
1033+ [ D.fillSep
1034+ ["Package","names","always","include","the","name","of","the","author,"
1035+ ,"so","I","am","expecting","to","see","dependencies","like"
1036+ ,D.dullyellow "\"mdgriffith/elm-ui\"","and"
1037+ ,D.dullyellow "\"Microsoft/elm-json-tree-view\"" <> "."
1038+ ]
1039+ , D.fillSep $
1040+ ["I","generally","recommend","finding","the","package","you","want","on"
1041+ ,"the","package","website,","and","installing","it","with","the"
1042+ ,D.green "elm install","command!"
1043+ ]
1044+ ]
1045+ )
9921046
993−-- RENDERERS
1047+ OP_BadLicense _ suggestions ->
1048+ toSnippet "UNKNOWN LICENSE" Nothing
1049+ ( D.reflow $
1050+ "I got stuck while reading your elm.json file. I do not know about this type of license:"
1051+ ,
1052+ D.stack
1053+ [ D.fillSep
1054+ ["Elm","packages","generally","use"
1055+ ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\"" <> ","
1056+ ,"but","I","accept","any","OSI","approved","SPDX","license."
1057+ ,"Here","some","that","seem","close","to","what","you","wrote:"
1058+ ]
1059+ , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Json.toChars) suggestions
1060+ , D.reflow $
1061+ "Check out https://spdx.org/licenses/ for the full list of options."
1062+ ]
1063+ )
9941064
1065+ OP_BadSummaryTooLong ->
1066+ toSnippet "SUMMARY TOO LONG" Nothing
1067+ ( D.reflow $
1068+ "I got stuck while reading your elm.json file. Your \"summary\" is too long:"
1069+ , D.fillSep
1070+ ["I","need","it","to","be"
1071+ ,D.green "under",D.green "80",D.green "characters"
1072+ ,"so","it","renders","nicely","on","the","package","website!"
1073+ ]
1074+ )
9951075
996−toString :: Help.Report -> String
997−toString report =
998− Help.toString (Help.reportToDoc report)
1076+ OP_NoSrcDirs ->
1077+ toSnippet "NO SOURCE DIRECTORIES" Nothing
1078+ ( D.reflow $
1079+ "I got stuck while reading your elm.json file. You do not have any \"source-directories\" listed here:"
1080+ , D.fillSep
1081+ ["I","need","something","like",D.green "[\"src\"]"
1082+ ,"so","I","know","where","to","look","for","your","modules!"
1083+ ]
1084+ )
9991085
10001086
1001−toStderr :: Help.Report -> IO ()
1002−toStderr report =
1003− Help.toStderr (Help.reportToDoc report)
10041087
1088+-- DETAILS
10051089
1006−toJson :: Help.Report -> Encode.Value
1007−toJson report =
1008− Help.reportToJson report
10091090
1091+data Details
1092+ = DetailsNoSolution
1093+ | DetailsNoOfflineSolution
1094+ | DetailsSolverProblem Solver
1095+ | DetailsBadElmInPkg C.Constraint
1096+ | DetailsBadElmInAppOutline V.Version
1097+ | DetailsHandEditedDependencies
1098+ | DetailsBadOutline Outline
1099+ | DetailsCannotGetRegistry RegistryProblem
1100+ | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
10101101
10111102
1012−-- DETAILS TO REPORT
1103+toDetailsReport :: Details -> Help.Report
1104+toDetailsReport details =
1105+ case details of
1106+ DetailsNoSolution ->
1107+ error "TODO DetailsNoSolution"
10131108
1109+ DetailsNoOfflineSolution ->
1110+ error "TODO DetailsNoOfflineSolution"
10141111
1015−detailsToReport :: Details -> Help.Report
1016−detailsToReport details =
1017− case details of
1018− DetailsCorrupt ->
1019− error "TODO DetailsCorrupt"
1112+ DetailsSolverProblem _ ->
1113+ error "TODO DetailsSolverProblem"
10201114
10211115 DetailsBadElmInPkg constraint ->
10221116 Help.report "ELM VERSION MISMATCH" (Just "elm.json")
@@ -1054,366 +1148,379 @@ detailsToReport details =
10541148 DetailsCannotBuildPackage name version problem ->
10551149 error "TODO DetailsCannotBuildPackage" name version problem
10561150
1057− DetailsNoSolution ->
1058− error "TODO DetailsNoSolution"
10591151
1060− DetailsNoOfflineSolution ->
1061− error "TODO DetailsNoOfflineSolution"
10621152
1063− DetailsSolverProblem _ ->
1064− error "TODO DetailsSolverProblem"
1153+-- PACKAGE PROBLEM
10651154
10661155
1156+data PackageProblem
1157+ = PP_BadEndpointRequest Http.Error
1158+ | PP_BadEndpointContent
1159+ | PP_BadArchiveRequest Http.Error
1160+ | PP_BadArchiveContent
1161+ | PP_BadArchiveHash String String
10671162
1068−makeToReport :: Make -> Help.Report
1069−makeToReport make =
1070− case make of
1071− MakeNeedsOutline ->
1072− Help.report "NO elm.json FILE" Nothing
1073− "It looks like you are starting a new Elm project. Very exciting! Try running:"
1074− [ D.indent 4 $ D.green $ "elm init"
1075− , D.reflow $
1076− "It will help you get set up. It is really simple!"
1077− ]
10781163
1079− MakeCannotOptimizeAndDebug ->
1080− Help.docReport "CLASHING FLAGS" Nothing
1081− ( D.fillSep
1082− ["I","cannot","compile","with",D.red "--optimize","and"
1083− ,D.red "--debug","at","the","same","time."
1084− ]
1085− )
1086− [ D.reflow
1087− "I need to take away information to optimize things, and I need to\
1088− \ add information to add the debugger. It is impossible to do both\
1089− \ at once though! Pick just one of those flags and it should work!"
1090− ]
10911164
1092− MakeBlockedByDetailsProblem detailsProblem ->
1093− detailsToReport detailsProblem
1165+-- REGISTRY PROBLEM
10941166
1095− MakeAppNeedsFileNames ->
1096− Help.report "NO INPUT" Nothing
1097− "What should I make though? I need a specific file like this:"
1098− [ D.indent 4 $ D.green "elm make src/Main.elm"
1099− , D.reflow
1100− "However many files you give, I will create one JS file out of them."
1101− ]
11021167
1103− MakePkgNeedsExposing ->
1104− error "TODO MakePkgNeedsExposing"
1168+data RegistryProblem
1169+ = RP_Http Http.Error
1170+ | RP_Data String BS.ByteString
11051171
1106− MakeMultipleFilesIntoHtml ->
1107− error "TODO MakeMultipleFilesIntoHtml"
11081172
1109− MakeNonMainFilesIntoJavaScript _ _ ->
1110− error "TODO MakeNonMainFilesIntoJavaScript"
1173+toRegistryProblemReport :: String -> RegistryProblem -> String -> Help.Report
1174+toRegistryProblemReport title problem context =
1175+ case problem of
1176+ RP_Http err ->
1177+ toHttpErrorReport title err context
11111178
1112− MakeCannotOptimizeDebugValues m ms ->
1113− Help.report "DEBUG REMNANTS" Nothing
1114− "There are uses of the `Debug` module in the following modules:"
1115− [ D.indent 4 $ D.red $ D.vcat $ map (D.fromChars . ModuleName.toChars) (m:ms)
1116− , D.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
1117− , D.toSimpleNote $
1118− "The issue is that --optimize strips out info needed by `Debug` functions.\
1119− \ Here are two examples:"
1120− , D.indent 4 $ D.reflow $
1121− "(1) It shortens record field names. This makes the generated JavaScript is\
1122− \ smaller, but `Debug.toString` cannot know the real field names anymore."
1123− , D.indent 4 $ D.reflow $
1124− "(2) Values like `type Height = Height Float` are unboxed. This reduces\
1125− \ allocation, but it also means that `Debug.toString` cannot tell if it is\
1126− \ looking at a `Height` or `Float` value."
1179+ RP_Data url body ->
1180+ Help.report title Nothing (context ++ ", so I fetched:")
1181+ [ D.indent 4 $ D.dullyellow $ D.fromChars url
11271182 , D.reflow $
1128− "There are a few other cases like that, and it will be much worse once we start\
1129− \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
1130− \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
1131− \ exists!"
1132− ]
1133−
1134− MakeCannotBuild buildProblem ->
1135− case buildProblem of
1136− BuildProjectProblem bp ->
1137− case bp of
1138− BP_PathUnknown _ ->
1139− error "TODO BP_PathUnknown"
1140−
1141− BP_WithBadExtension _ ->
1142− error "TODO BP_WithBadExtension"
1143−
1144− BP_WithAmbiguousSrcDir _ _ ->
1145− error "TODO BP_WithAmbiguousSrcDir"
1146−
1147− BP_MainPathDuplicate _ _ ->
1148− error "TODO BP_MainPathDuplicate"
1149−
1150− BP_MainNameDuplicate _ _ _ ->
1151− error "TODO BP_MainNameDuplicate"
1152−
1153− BP_CannotLoadDependencies ->
1154− error "TODO BP_CannotLoadDependencies"
1155−
1156− BP_Cycle name names ->
1157− Help.report "IMPORT CYCLE" Nothing
1158− "Your module imports form a cycle:"
1159− [ D.cycle 4 name names
1160− , D.reflow $
1161− "Learn more about why this is disallowed and how to break cycles here:"
1162− ++ D.makeLink "import-cycles"
1163− ]
1164−
1165− BP_MissingExposed _ ->
1166− error "TODO BP_MissingExposed"
1167−
1168− BuildModuleProblems p ps ->
1169− Help.compilerReport p ps
1170−
1171− MakeCannotLoadArtifacts ->
1172− error "TODO MakeCannotLoadArtifacts"
1173−
1174−
1183+ "I got the data back, but it was not what I was expecting. The response\
1184+ \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
1185+ ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
1186+ , D.indent 4 $ D.dullyellow $ D.fromChars $
1187+ if BS.length body <= 76
1188+ then BS_UTF8.toString body
1189+ else take 73 (BS_UTF8.toString body) ++ "..."
1190+ , D.reflow $
1191+ "Does this error keep showing up? Maybe there is something weird with your\
1192+ \ internet connection. We have gotten reports that schools, businesses,\
1193+ \ airports, etc. sometimes intercept requests and add things to the body\
1194+ \ or change its contents entirely. Could that be the problem?"
1195+ ]
11751196
1176−-- OUTLINE
11771197
1198+toHttpErrorReport :: String -> Http.Error -> String -> Help.Report
1199+toHttpErrorReport title err context =
1200+ let
1201+ toHttpReport intro url details =
1202+ Help.report title Nothing intro $
1203+ D.indent 4 (D.dullyellow (D.fromChars url)) : details
1204+ in
1205+ case err of
1206+ Http.BadUrl url reason ->
1207+ toHttpReport (context ++ ", so I wanted to fetch:") url
1208+ [ D.reflow $ "But my HTTP library is saying this is not a valid URL. It is saying:"
1209+ , D.indent 4 $ D.fromChars reason
1210+ , D.reflow $
1211+ "This may indicate that there is some problem in the compiler, so please open an\
1212+ \ issue at https://github.com/elm/compiler/issues listing your operating system, Elm\
1213+ \ version, the command you ran, the terminal output, and any additional information\
1214+ \ that might help others reproduce the error."
1215+ ]
11781216
1179−toOutlineReport :: Outline -> Help.Report
1180−toOutlineReport problem =
1181− case problem of
1182− OutlineHasBadStructure decodeError ->
1183− Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError $
1184− Json.ExplicitReason "I ran into a problem with your elm.json file."
1217+ Http.BadHttp url httpExceptionContent ->
1218+ case httpExceptionContent of
1219+ HTTP.StatusCodeException response _ ->
1220+ let
1221+ (HTTP.Status code message) = HTTP.responseStatus response
1222+ in
1223+ toHttpReport (context ++ ", so I tried to fetch:") url
1224+ [ D.fillSep $
1225+ ["But","it","came","back","as",D.red (D.fromInt code)]
1226+ ++ map D.fromChars (words (BS_UTF8.toString message))
1227+ , D.reflow $
1228+ "This may mean some online endpoint changed in an unexpected way, so if does not\
1229+ \ seem like something on your side is causing this (e.g. firewall) please report\
1230+ \ this to https://github.com/elm/compiler/issues with your operating system, Elm\
1231+ \ version, the command you ran, the terminal output, and any additional information\
1232+ \ that can help others reproduce the error!"
1233+ ]
11851234
1186− OutlineHasBadSrcDirs dir dirs ->
1187− case dirs of
1188− [] ->
1189− Help.report "MISSING SOURCE DIRECTORY" (Just "elm.json")
1190− "I need a valid elm.json file, but the \"source-directories\" field lists the following directory:"
1191− [ D.indent 4 $ D.dullyellow $ D.fromChars dir
1235+ HTTP.TooManyRedirects responses ->
1236+ toHttpReport (context ++ ", so I tried to fetch:") url
1237+ [ D.reflow $ "But I gave up after following these " ++ show (length responses) ++ " redirects:"
1238+ , D.indent 4 $ D.vcat $ map toRedirectDoc responses
11921239 , D.reflow $
1193− "I cannot find it though. Is it missing? Is there a typo?"
1240+ "Is it possible that your internet connection intercepts certain requests? That\
1241+ \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
1242+ \ and certain countries. Try asking for help locally or in a community forum!"
11941243 ]
11951244
1196− _:_ ->
1197− Help.report "MISSING SOURCE DIRECTORIES" (Just "elm.json")
1198− "I need a valid elm.json file, but the \"source-directories\" field lists the following directories:"
1199− [ D.indent 4 $ D.dullyellow $ D.fromChars dir
1245+ otherException ->
1246+ toHttpReport (context ++ ", so I tried to fetch:") url
1247+ [ D.reflow $ "But my HTTP library is giving me the following error message:"
1248+ , D.indent 4 $ D.fromChars (show otherException)
12001249 , D.reflow $
1201− "I cannot find them though. Are they missing? Are there typos?"
1250+ "Are you somewhere with a slow internet connection? Or no internet?\
1251+ \ Does the link I am trying to fetch work in your browser? Maybe the\
1252+ \ site is down? Does your internet connection have a firewall that\
1253+ \ blocks certain domains? It is usually something like that!"
12021254 ]
12031255
1204− OutlineNoPkgCore ->
1205− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1206− "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
1207− [ D.indent 4 $ D.green $ "elm install elm/core"
1208− , D.reflow "I need it for the default imports that make `List` and `Maybe` available."
1256+ Http.BadMystery url someException ->
1257+ toHttpReport (context ++ ", so I tried to fetch:") url
1258+ [ D.reflow $ "But I ran into something weird! I was able to extract this error message:"
1259+ , D.indent 4 $ D.fromChars (show someException)
1260+ , D.reflow $
1261+ "Is it possible that your internet connection intercepts certain requests? That\
1262+ \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
1263+ \ and certain countries. Try asking for help locally or in a community forum!"
12091264 ]
12101265
1211− OutlineNoAppCore ->
1212− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1213− "I need a valid elm.json file, so I need to see an \"elm/core\" dependency in there. Try running:"
1214− [ D.indent 4 $ D.green $ "elm install elm/core"
1215− , D.reflow "It has some supporting code that is needed by every Elm application!"
1216− ]
12171266
1218− OutlineNoAppJson ->
1219− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1220− "I need a valid elm.json file, so I need to see an \"elm/json\" dependency in there. Try running:"
1221− [ D.indent 4 $ D.green $ "elm install elm/json"
1222− , D.reflow "It helps me handle flags and ports."
1223− ]
1267+toRedirectDoc :: HTTP.Response body -> D.Doc
1268+toRedirectDoc response =
1269+ let
1270+ (HTTP.Status code message) = HTTP.responseStatus response
1271+ in
1272+ case List.lookup HTTP.hLocation (HTTP.responseHeaders response) of
1273+ Just loc -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString loc)
1274+ Nothing -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString message)
12241275
12251276
1226−toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
1227−toOutlineProblemReport path source _ region problem =
1228− let
1229− toHighlight row col =
1230− Just $ A.Region (A.Position row col) (A.Position row col)
12311277
1232− toSnippet title highlight pair =
1233− Help.jsonReport title (Just path) $
1234− Code.toSnippet source region highlight pair
1235− in
1236− case problem of
1237− OP_BadType ->
1238− toSnippet "UNEXPECTED TYPE" Nothing
1239− ( D.reflow $
1240− "I got stuck while reading your elm.json file. I cannot handle a \"type\" like this:"
1241− , D.fillSep
1242− ["Try","changing","the","\"type\"","to"
1243− ,D.green "\"application\"","or",D.green "\"package\"","instead."
1244− ]
1245− )
1278+-- MAKE
12461279
1247− OP_BadPkgName row col ->
1248− toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
1249− ( D.reflow $
1250− "I got stuck while reading your elm.json file. I ran into trouble with the package name:"
1251− , D.stack
1252− [ D.fillSep
1253− ["Package","names","are","always","written","as"
1254− ,D.green "\"author/project\""
1255− ,"so","I","am","expecting","to","see","something","like:"
1256− ]
1257− , D.dullyellow $ D.indent 4 $ D.vcat $
1258− [ "\"mdgriffith/elm-ui\""
1259− , "\"w0rm/elm-physics\""
1260− , "\"Microsoft/elm-json-tree-view\""
1261− , "\"FordLabs/elm-star-rating\""
1262− , "\"1602/json-schema\""
1263− ]
1264− , D.reflow
1265− "The author name should match your GitHub name exactly, and the project name\
1266− \ needs to follow these rules:"
1267− , D.indent 4 $ D.vcat $
1268− [ "+--------------------------------------+-----------+-----------+"
1269− , "| RULE | BAD | GOOD |"
1270− , "+--------------------------------------+-----------+-----------+"
1271− , "| only lower case, digits, and hyphens | elm-HTTP | elm-http |"
1272− , "| no leading digits | 3D | elm-3d |"
1273− , "| no non-ASCII characters | elm-bjørn | elm-bear |"
1274− , "| no underscores | elm_ui | elm-ui |"
1275− , "| no double hyphens | elm--hash | elm-hash |"
1276− , "| no starting or ending hyphen | -elm-tar- | elm-tar |"
1277− , "+--------------------------------------+-----------+-----------+"
1278− ]
1279− , D.toSimpleNote $
1280− "These rules only apply to the project name, so you should never need\
1281− \ to change your GitHub name!"
1282− ]
1283− )
12841280
1285− OP_BadVersion row col ->
1286− toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
1287− ( D.reflow $
1288− "I got stuck while reading your elm.json file. I was expecting a version number here:"
1289− , D.fillSep
1290− ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
1291− ,"that","explicitly","states","all","three","numbers!"
1281+data Make
1282+ = MakeNoOutline
1283+ | MakeCannotOptimizeAndDebug
1284+ | MakeBlockedByDetailsProblem Details
1285+ | MakeAppNeedsFileNames
1286+ | MakePkgNeedsExposing
1287+ | MakeMultipleFilesIntoHtml
1288+ | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
1289+ | MakeCannotBuild BuildProblem
1290+ | MakeBadGenerate Generate
1291+
1292+
1293+makeToReport :: Make -> Help.Report
1294+makeToReport make =
1295+ case make of
1296+ MakeNoOutline ->
1297+ Help.report "NO elm.json FILE" Nothing
1298+ "It looks like you are starting a new Elm project. Very exciting! Try running:"
1299+ [ D.indent 4 $ D.green $ "elm init"
1300+ , D.reflow $
1301+ "It will help you get set up. It is really simple!"
1302+ ]
1303+
1304+ MakeCannotOptimizeAndDebug ->
1305+ Help.docReport "CLASHING FLAGS" Nothing
1306+ ( D.fillSep
1307+ ["I","cannot","compile","with",D.red "--optimize","and"
1308+ ,D.red "--debug","at","the","same","time."
12921309 ]
12931310 )
1311+ [ D.reflow
1312+ "I need to take away information to optimize things, and I need to\
1313+ \ add information to add the debugger. It is impossible to do both\
1314+ \ at once though! Pick just one of those flags and it should work!"
1315+ ]
12941316
1295− OP_BadConstraint constraintError ->
1296− case constraintError of
1297− C.BadFormat row col ->
1298− toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
1299− ( D.reflow $
1300− "I got stuck while reading your elm.json file. I do not understand this version constraint:"
1301− , D.stack
1302− [ D.fillSep
1303− ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
1304− ,"that","explicitly","lists","the","lower","and","upper","bounds."
1305− ]
1306− , D.toSimpleNote $
1307− "The spaces in there are required! Taking them out will confuse me. Adding\
1308− \ extra spaces confuses me too. I recommend starting with a valid example\
1309− \ and just changing the version numbers."
1310− ]
1311− )
1317+ MakeBlockedByDetailsProblem detailsProblem ->
1318+ toDetailsReport detailsProblem
13121319
1313− C.InvalidRange before after ->
1314− if before == after then
1315− toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1316− ( D.reflow $
1317− "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1318− , D.fillSep
1319− ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
1320− ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
1321− ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor after) <> "\""
1322− ,"since","it","is","guaranteed","that","breaking","API","changes","cannot"
1323− ,"happen","in","any","of","the","versions","in","that","range."
1324− ]
1325− )
1320+ MakeAppNeedsFileNames ->
1321+ Help.report "NO INPUT" Nothing
1322+ "What should I make though? I need a specific file like this:"
1323+ [ D.indent 4 $ D.green "elm make src/Main.elm"
1324+ , D.reflow
1325+ "However many files you give, I will create one JS file out of them."
1326+ ]
13261327
1327− else
1328− toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1329− ( D.reflow $
1330− "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1331− , D.fillSep
1332− ["Maybe","you","want","something","like"
1333− ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
1334− ,"instead?","Elm","checks","that","all","package","APIs","follow","semantic"
1335− ,"versioning,","so","it","is","guaranteed","that","breaking","API","changes"
1336− ,"cannot","happen","in","any","of","the","versions","in","that","range."
1337− ]
1338− )
1328+ MakePkgNeedsExposing ->
1329+ error "TODO MakePkgNeedsExposing"
13391330
1340− OP_BadModuleName row col ->
1341− toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
1342− ( D.reflow $
1343− "I got stuck while reading your elm.json file. I was expecting a module name here:"
1344− , D.fillSep
1345− ["I","need","something","like",D.green "\"Html.Events\""
1346− ,"or",D.green "\"Browser.Navigation\""
1347− ,"where","each","segment","starts","with","a","capital"
1348− ,"letter","and","the","segments","are","separated","by","dots."
1331+ MakeMultipleFilesIntoHtml ->
1332+ error "TODO MakeMultipleFilesIntoHtml"
1333+
1334+ MakeNonMainFilesIntoJavaScript _ _ ->
1335+ error "TODO MakeNonMainFilesIntoJavaScript"
1336+
1337+ MakeCannotBuild buildProblem ->
1338+ toBuildProblemReport buildProblem
1339+
1340+ MakeBadGenerate generateProblem ->
1341+ toGenerateReport generateProblem
1342+
1343+
1344+
1345+-- BUILD PROBLEM
1346+
1347+
1348+data BuildProblem
1349+ = BuildModuleProblems Error.Module [Error.Module]
1350+ | BuildProjectProblem BuildProjectProblem
1351+
1352+
1353+data BuildProjectProblem
1354+ = BP_PathUnknown FilePath
1355+ | BP_WithBadExtension FilePath
1356+ | BP_WithAmbiguousSrcDir FilePath FilePath FilePath
1357+ | BP_MainPathDuplicate FilePath FilePath
1358+ | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
1359+ | BP_CannotLoadDependencies
1360+ | BP_Cycle ModuleName.Raw [ModuleName.Raw]
1361+ | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
1362+
1363+
1364+toBuildProblemReport :: BuildProblem -> Help.Report
1365+toBuildProblemReport problem =
1366+ case problem of
1367+ BuildModuleProblems p ps ->
1368+ Help.compilerReport p ps
1369+
1370+ BuildProjectProblem projectProblem ->
1371+ case projectProblem of
1372+ BP_PathUnknown path ->
1373+ Help.report "FILE NOT FOUND" Nothing
1374+ "I cannot find this file:"
1375+ [ D.indent 4 $ D.red $ D.fromChars path
1376+ , D.reflow $ "Is there a typo?"
1377+ , D.toSimpleNote $
1378+ "If you are just getting started, try working through the examples in the\
1379+ \ official guide https://guide.elm-lang.org to get an idea of the kinds of things\
1380+ \ that typically go in a src/Main.elm file."
13491381 ]
1350− )
13511382
1352− OP_BadModuleHeaderTooLong ->
1353− toSnippet "HEADER TOO LONG" Nothing
1354− ( D.reflow $
1355− "I got stuck while reading your elm.json file. This section header is too long:"
1356− , D.fillSep
1357− ["I","need","it","to","be"
1358− ,D.green "under",D.green "20",D.green "characters"
1359− ,"so","it","renders","nicely","on","the","package","website!"
1383+ BP_WithBadExtension path ->
1384+ Help.report "UNEXPECTED FILE EXTENSION" Nothing
1385+ "I can only compile Elm files (with a .elm extension) but you want me to compile:"
1386+ [ D.indent 4 $ D.red $ D.fromChars path
1387+ , D.reflow $ "Is there a typo? Can the file extension be changed?"
13601388 ]
1361− )
13621389
1363− OP_BadDependencyName row col ->
1364− toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
1365− ( D.reflow $
1366− "I got stuck while reading your elm.json file. There is something wrong with this dependency name:"
1367− , D.stack
1368− [ D.fillSep
1369− ["Package","names","always","include","the","name","of","the","author,"
1370− ,"so","I","am","expecting","to","see","dependencies","like"
1371− ,D.dullyellow "\"mdgriffith/elm-ui\"","and"
1372− ,D.dullyellow "\"Microsoft/elm-json-tree-view\"" <> "."
1373− ]
1374− , D.fillSep $
1375− ["I","generally","recommend","finding","the","package","you","want","on"
1376− ,"the","package","website,","and","installing","it","with","the"
1377− ,D.green "elm install","command!"
1378− ]
1390+ BP_WithAmbiguousSrcDir path srcDir1 srcDir2 ->
1391+ Help.report "CONFUSING FILE" Nothing
1392+ "I am getting confused when I try to compile this file:"
1393+ [ D.indent 4 $ D.red $ D.fromChars path
1394+ , D.reflow $
1395+ "I always check if files appear in any of the \"source-directories\" listed in\
1396+ \ your elm.json to see if there might be some cached information about them. That\
1397+ \ can help me compile faster! But in this case, it looks like this file may be in\
1398+ \ either of these directories:"
1399+ , D.indent 4 $ D.red $ D.vcat $ map D.fromChars [srcDir1,srcDir2]
1400+ , D.reflow $
1401+ "Try to make it so no source directory contains another source directory!"
13791402 ]
1380− )
13811403
1382− OP_BadLicense _ suggestions ->
1383− toSnippet "UNKNOWN LICENSE" Nothing
1384− ( D.reflow $
1385− "I got stuck while reading your elm.json file. I do not know about this type of license:"
1386− ,
1387− D.stack
1388− [ D.fillSep
1389− ["Elm","packages","generally","use"
1390− ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\"" <> ","
1391− ,"but","I","accept","any","OSI","approved","SPDX","license."
1392− ,"Here","some","that","seem","close","to","what","you","wrote:"
1393− ]
1394− , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Json.toChars) suggestions
1404+ BP_MainPathDuplicate path1 path2 ->
1405+ Help.report "CONFUSING FILES" Nothing
1406+ "You are telling me to compile these two files:"
1407+ [ D.indent 4 $ D.red $ D.vcat $ map D.fromChars [ path1, path2 ]
13951408 , D.reflow $
1396− "Check out https://spdx.org/licenses/ for the full list of options."
1409+ if path1 == path2 then
1410+ "Why are you telling me twice? Is something weird going on with a script?\
1411+ \ I figured I would let you know about it just in case something is wrong.\
1412+ \ Only list it once and you should be all set!"
1413+ else
1414+ "But seem to be the same file though... It makes me think something tricky is\
1415+ \ going on with symlinks in your project, so I figured I would let you know\
1416+ \ about it just in case. Remove one of these files from your command to get\
1417+ \ unstuck!"
13971418 ]
1398− )
13991419
1400− OP_BadSummaryTooLong ->
1401− toSnippet "SUMMARY TOO LONG" Nothing
1402− ( D.reflow $
1403− "I got stuck while reading your elm.json file. Your \"summary\" is too long:"
1404− , D.fillSep
1405− ["I","need","it","to","be"
1406− ,D.green "under",D.green "80",D.green "characters"
1407− ,"so","it","renders","nicely","on","the","package","website!"
1420+ BP_MainNameDuplicate name outsidePath otherPath ->
1421+ Help.report "MODULE NAME CLASH" Nothing
1422+ "These two files are causing a module name clash:"
1423+ [ D.indent 4 $ D.red $ D.vcat $ map D.fromChars [ outsidePath, otherPath ]
1424+ , D.reflow $
1425+ "They both say `module " ++ ModuleName.toChars name ++ " exposing (..)` up\
1426+ \ at the top, but they cannot have the same name!"
1427+ , D.reflow $
1428+ "Try changing to a different module name in one of them!"
14081429 ]
1409− )
14101430
1411− OP_NoSrcDirs ->
1412− toSnippet "NO SOURCE DIRECTORIES" Nothing
1413− ( D.reflow $
1414− "I got stuck while reading your elm.json file. You do not have any \"source-directories\" listed here:"
1415− , D.fillSep
1416− ["I","need","something","like",D.green "[\"src\"]"
1417− ,"so","I","know","where","to","look","for","your","modules!"
1431+ BP_CannotLoadDependencies ->
1432+ corruptCacheReport
1433+
1434+ BP_Cycle name names ->
1435+ Help.report "IMPORT CYCLE" Nothing
1436+ "Your module imports form a cycle:"
1437+ [ D.cycle 4 name names
1438+ , D.reflow $
1439+ "Learn more about why this is disallowed and how to break cycles here:"
1440+ ++ D.makeLink "import-cycles"
14181441 ]
1419− )
1442+
1443+ BP_MissingExposed _ ->
1444+ error "TODO BP_MissingExposed"
1445+
1446+
1447+
1448+-- GENERATE
1449+
1450+
1451+data Generate
1452+ = GenerateCannotLoadArtifacts
1453+ | GenerateCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
1454+
1455+
1456+toGenerateReport :: Generate -> Help.Report
1457+toGenerateReport problem =
1458+ case problem of
1459+ GenerateCannotLoadArtifacts ->
1460+ corruptCacheReport
1461+
1462+ GenerateCannotOptimizeDebugValues m ms ->
1463+ Help.report "DEBUG REMNANTS" Nothing
1464+ "There are uses of the `Debug` module in the following modules:"
1465+ [ D.indent 4 $ D.red $ D.vcat $ map (D.fromChars . ModuleName.toChars) (m:ms)
1466+ , D.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
1467+ , D.toSimpleNote $
1468+ "The issue is that --optimize strips out info needed by `Debug` functions.\
1469+ \ Here are two examples:"
1470+ , D.indent 4 $ D.reflow $
1471+ "(1) It shortens record field names. This makes the generated JavaScript is\
1472+ \ smaller, but `Debug.toString` cannot know the real field names anymore."
1473+ , D.indent 4 $ D.reflow $
1474+ "(2) Values like `type Height = Height Float` are unboxed. This reduces\
1475+ \ allocation, but it also means that `Debug.toString` cannot tell if it is\
1476+ \ looking at a `Height` or `Float` value."
1477+ , D.reflow $
1478+ "There are a few other cases like that, and it will be much worse once we start\
1479+ \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
1480+ \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
1481+ \ exists!"
1482+ ]
1483+
1484+
1485+
1486+-- CORRUPT CACHE
1487+
1488+
1489+corruptCacheReport :: Help.Report
1490+corruptCacheReport =
1491+ Help.report "CORRUPT CACHE" Nothing
1492+ "It looks like some of the information cached in elm-stuff/ has been corrupted."
1493+ [ D.reflow $
1494+ "Try deleting your elm-stuff/ directory to get unstuck."
1495+ , D.toSimpleNote $
1496+ "This almost certainly means that a 3rd party tool (or editor plugin) is\
1497+ \ causing problems your the elm-stuff/ directory. Try disabling 3rd party tools\
1498+ \ one by one until you figure out which it is!"
1499+ ]
1500+
1501+
1502+
1503+-- REACTOR
1504+
1505+
1506+data Reactor
1507+ = ReactorNoOutline
1508+ | ReactorBadDetails Details
1509+ | ReactorBadBuild BuildProblem
1510+ | ReactorBadGenerate Generate
1511+
1512+
1513+reactorToReport :: Reactor -> Help.Report
1514+reactorToReport problem =
1515+ case problem of
1516+ ReactorNoOutline ->
1517+ error "TODO ReactorNoOutline"
1518+
1519+ ReactorBadDetails details ->
1520+ error "TODO ReactorBadDetails" details
1521+
1522+ ReactorBadBuild buildProblem ->
1523+ error "TODO ReactorBadBuild" buildProblem
1524+
1525+ ReactorBadGenerate generate ->
1526+ toGenerateReport generate