on master help sign in
add error messages for bad elm.json
commitf65ee90a3ee21c08483c56137b625fdd49662daf authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 12 Jun 2019, 17:20 (7 years ago) parent1468046
1 file changed+180−17
builder/src/Reporting/Exit.hs+180−17
builder/src/Reporting/Exit.hs+180−17
@@ -41,7 +41,6 @@ module Reporting.Exit
4141
4242import qualified Data.List as List
4343import qualified Data.NonEmptyList as NE
44−import qualified Data.Utf8 as Utf8
4544
4645import qualified Elm.Constraint as C
4746import qualified Elm.Magnitude as M
@@ -53,12 +52,14 @@ import qualified Json.Decode as Decode
5352import qualified Json.Encode as Encode
5453import qualified Json.String as Json
5554import Parse.Primitives (Row, Col)
55+import qualified Reporting.Annotation as A
5656import Reporting.Doc ((<>))
5757import qualified Reporting.Doc as D
5858import qualified Reporting.Error.Import as Import
5959import qualified Reporting.Error.Json as Json
6060import qualified Reporting.Exit.Help as Help
6161import qualified Reporting.Error as Error
62+import qualified Reporting.Render.Code as Code
6263
6364
6465
@@ -608,7 +609,7 @@ installToReport exit =
608609 Help.report "OLD DEPENDENCIES" (Just "elm.json")
609610 ( "The following packages do not work with Elm " ++ V.toChars V.compiler ++ " right now:"
610611 )
611− [ D.indent 4 $ D.vcat $ map (D.red . D.fromUtf8 . Pkg.toString) badPackages
612+ [ D.indent 4 $ D.vcat $ map (D.red . D.fromPackage) badPackages
612613 , D.reflow $
613614 "This may be because it is not upgraded yet. It may be because a\
614615 \ better solution came along, so there was no need to upgrade it.\
@@ -912,7 +913,7 @@ toOutlineReport :: Outline -> Help.Report
912913toOutlineReport problem =
913914 case problem of
914915 OutlineHasBadStructure decodeError ->
915− error "TODO OutlineHasBadStructure" decodeError toOutlineProblemReport
916+ Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError
916917
917918 OutlineHasBadSrcDirs dir dirs ->
918919 case dirs of
@@ -953,36 +954,198 @@ toOutlineReport problem =
953954 , D.reflow "It helps me handle flags and ports."
954955 ]
955956
956−toOutlineProblemReport :: OutlineProblem -> Help.Report
957−toOutlineProblemReport problem =
957+
958+toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
959+toOutlineProblemReport path source _ region problem =
960+ let
961+ toHighlight row col =
962+ Just $ A.Region (A.Position row col) (A.Position row col)
963+
964+ toSnippet title highlight pair =
965+ Help.jsonReport title (Just path) $
966+ Code.toSnippet source region highlight pair
967+ in
958968 case problem of
959969 OP_BadType ->
960− error "TODO OP_BadType"
970+ toSnippet "UNEXPECTED TYPE" Nothing
971+ ( D.reflow $
972+ "I do not know how to process this type of elm.json file:"
973+ , D.fillSep
974+ ["Try","changing","the","type","to"
975+ ,D.green "\"application\"","or",D.green "\"package\"","instead."
976+ ]
977+ )
961978
962979 OP_BadPkgName row col ->
963− error "TODO OP_BadPkgName" row col
980+ toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
981+ ( D.reflow $
982+ "I ran into trouble with this package name:"
983+ , D.stack
984+ [ D.fillSep
985+ ["Package","names","are","always","written","as"
986+ ,D.green "\"author/project\""
987+ ,"so","I","am","expecting","to","see","something","like:"
988+ ]
989+ , D.dullyellow $ D.indent 4 $ D.vcat $
990+ [ "\"mdgriffith/elm-ui\""
991+ , "\"w0rm/elm-physics\""
992+ , "\"Microsoft/elm-json-tree-view\""
993+ , "\"FordLabs/elm-star-rating\""
994+ , "\"1602/json-schema\""
995+ ]
996+ , D.reflow
997+ "The author name should match your GitHub name exactly, and the project name\
998+ \ needs to follow these rules:"
999+ , D.indent 4 $ D.vcat $
1000+ [ "+--------------------------------------+-----------+-----------+"
1001+ , "| RULE | BAD | GOOD |"
1002+ , "+--------------------------------------+-----------+-----------+"
1003+ , "| only lower case, digits, and hyphens | elm-HTTP | elm-http |"
1004+ , "| no leading digits | 3D | elm-3d |"
1005+ , "| no non-ASCII characters | elm-bjørn | elm-bear |"
1006+ , "| no underscores | elm_ui | elm-ui |"
1007+ , "| no double hyphens | elm--hash | elm-hash |"
1008+ , "| no starting or ending hyphen | -elm-tar- | elm-tar |"
1009+ , "+--------------------------------------+-----------+-----------+"
1010+ ]
1011+ , D.toSimpleNote $
1012+ "These rules only apply to the project name, so you should never need\
1013+ \ to change your GitHub name!"
1014+ ]
1015+ )
9641016
9651017 OP_BadVersion row col ->
966− error "TODO OP_BadVersion" row col
1018+ toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
1019+ ( D.reflow $
1020+ "I was expecting a version number here:"
1021+ , D.fillSep
1022+ ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
1023+ ,"that","explicitly","states","all","three","numbers!"
1024+ ]
1025+ )
9671026
9681027 OP_BadConstraint constraintError ->
969− error "TODO OP_BadConstraint" constraintError
1028+ case constraintError of
1029+ C.BadFormat row col ->
1030+ toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
1031+ ( D.reflow $
1032+ "I was expecting a version constraint here:"
1033+ , D.stack
1034+ [ D.fillSep
1035+ ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
1036+ ,"that","explicitly","lists","the","lower","and","upper","bounds."
1037+ ]
1038+ , D.toSimpleNote $
1039+ "The spaces in there are required! Taking them out will confuse me. Adding\
1040+ \ extra spaces confuses me too. I recommend starting with a valid example\
1041+ \ and just changing the version numbers."
1042+ ]
1043+ )
1044+
1045+ C.InvalidRange before after ->
1046+ if before == after then
1047+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1048+ ( D.reflow $
1049+ "I ran into an invalid version constraint:"
1050+ , D.fillSep
1051+ ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
1052+ ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
1053+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor after) <> "\""
1054+ ,"since","it","is","guaranteed","that","breaking","API","changes","cannot"
1055+ ,"happen","in","any","of","the","versions","in","that","range."
1056+ ]
1057+ )
1058+
1059+ else
1060+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1061+ ( D.reflow $
1062+ "I ran into an invalid version constraint:"
1063+ , D.fillSep
1064+ ["Maybe","you","want","something","like"
1065+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
1066+ ,"instead?","Elm","checks","that","all","package","APIs","follow","semantic"
1067+ ,"versioning,","so","it","is","guaranteed","that","breaking","API","changes"
1068+ ,"cannot","happen","in","any","of","the","versions","in","that","range."
1069+ ]
1070+ )
9701071
9711072 OP_BadModuleName row col ->
972− error "TODO OP_BadModuleName" row col
1073+ toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
1074+ ( D.reflow $
1075+ "I was expecting a module name here:"
1076+ , D.fillSep
1077+ ["I","need","something","like",D.green "\"Html.Events\""
1078+ ,"or",D.green "\"Browser.Navigation\""
1079+ ,"where","each","segment","starts","with","a","capital"
1080+ ,"letter","and","the","segments","are","separated","by","dots."
1081+ ]
1082+ )
9731083
9741084 OP_BadModuleHeaderTooLong ->
975− error "TODO OP_BadModuleHeaderTooLong"
1085+ toSnippet "HEADER TOO LONG" Nothing
1086+ ( D.reflow $
1087+ "This section header is too long:"
1088+ , D.fillSep
1089+ ["I","need","it","to","be"
1090+ ,D.green "under",D.green "20",D.green "characters"
1091+ ,"so","it","renders","nicely","on","the","package","website!"
1092+ ]
1093+ )
9761094
9771095 OP_BadDependencyName row col ->
978− error "TODO OP_BadDependencyName"
1096+ toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
1097+ ( D.reflow $
1098+ "There is something wrong with this dependency name:"
1099+ , D.stack
1100+ [ D.fillSep
1101+ ["Package","names","always","include","the","name","of","the","author,"
1102+ ,"so","I","am","expecting","to","see","dependencies","like"
1103+ ,D.dullyellow "\"mdgriffith/elm-ui\"","and"
1104+ ,D.dullyellow "\"Microsoft/elm-json-tree-view\"" <> "."
1105+ ]
1106+ , D.fillSep $
1107+ ["I","generally","recommend","finding","the","package","you","want","on"
1108+ ,"the","package","website,","and","installing","it","with","the"
1109+ ,D.green "elm install","command!"
1110+ ]
1111+ ]
1112+ )
9791113
980− OP_BadLicense badLicense suggestions ->
981− error "TODO OP_BadLicense" badLicense suggestions
1114+ OP_BadLicense _ suggestions ->
1115+ toSnippet "UNKNOWN LICENSE" Nothing
1116+ ( D.reflow $
1117+ "I do not know about this type of license:"
1118+ ,
1119+ D.stack
1120+ [ D.fillSep
1121+ ["Elm","packages","generally","use"
1122+ ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\"" <> ","
1123+ ,"but","I","accept","any","OSI","approved","SPDX","license."
1124+ ,"Here","some","that","seem","close","to","what","you","wrote:"
1125+ ]
1126+ , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Json.toChars) suggestions
1127+ , D.reflow $
1128+ "Check out https://spdx.org/licenses/ for the full list of options."
1129+ ]
1130+ )
9821131
9831132 OP_BadSummaryTooLong ->
984− error "TODO OP_BadSummaryTooLong"
1133+ toSnippet "SUMMARY TOO LONG" Nothing
1134+ ( D.reflow $
1135+ "Your \"summary\" is too long:"
1136+ , D.fillSep
1137+ ["I","need","it","to","be"
1138+ ,D.green "under",D.green "80",D.green "characters"
1139+ ,"so","it","renders","nicely","on","the","package","website!"
1140+ ]
1141+ )
9851142
9861143 OP_NoSrcDirs ->
987− error "TODO OP_NoSrcDirs"
988−
1144+ toSnippet "NO SOURCE DIRECTORIES" Nothing
1145+ ( D.reflow $
1146+ "You do not have any \"source-directories\" listed here:"
1147+ , D.fillSep
1148+ ["I","need","something","like",D.green "[\"src\"]"
1149+ ,"so","I","know","where","to","look","for","your","modules!"
1150+ ]
1151+ )