on master help sign in
Improve some other error messages about unknown packages
d4e9599Evan Czaplicki
builder/src/Deps/Explorer.hs+3−3
@@ -73,8 +73,8 @@ exists name =
73 Right _ ->
73 Right _ ->
74 return ()
74 return ()
75
75
76− Left allPkgs ->
76+ Left suggestions ->
77− throwError (Exit.Deps (E.PackageNotFound name allPkgs))
77+ throwError (Exit.Deps (E.PackageNotFound name suggestions))
78
78
79
79
80
80
@@ -88,7 +88,7 @@ getVersions name =
88 Right versions ->
88 Right versions ->
89 return versions
89 return versions
90
90
91− Left _allPkgs ->
91+ Left _suggestions ->
92 throwError (Exit.Deps (E.CorruptVersionCache name))
92 throwError (Exit.Deps (E.CorruptVersionCache name))
93
93
94
94
builder/src/Deps/Get.hs+31−1
@@ -14,15 +14,18 @@ module Deps.Get
14import Prelude hiding (all)
14import Prelude hiding (all)
15import Control.Monad.Except (catchError, liftIO)
15import Control.Monad.Except (catchError, liftIO)
16import qualified Data.ByteString as BS
16import qualified Data.ByteString as BS
17+import Data.Function (on)
17import qualified Data.List as List
18import qualified Data.List as List
18import qualified Data.Map as Map
19import qualified Data.Map as Map
19import Data.Map (Map)
20import Data.Map (Map)
21+import qualified Data.Text as Text
20import qualified System.Directory as Dir
22import qualified System.Directory as Dir
21import System.FilePath ((</>))
23import System.FilePath ((</>))
22import qualified Text.PrettyPrint.ANSI.Leijen as P
24import qualified Text.PrettyPrint.ANSI.Leijen as P
23
25
24import qualified Elm.Docs as Docs
26import qualified Elm.Docs as Docs
25import qualified Elm.Package as Pkg
27import qualified Elm.Package as Pkg
28+import qualified Elm.Utils as Utils
26
29
27import qualified Deps.Website as Website
30import qualified Deps.Website as Website
28import qualified Elm.Project.Json as Project
31import qualified Elm.Project.Json as Project
@@ -100,7 +103,34 @@ versions name (AllPackages pkgs) =
100 Right vsns
103 Right vsns
101
104
102 Nothing ->
105 Nothing ->
103− Left (Map.keys pkgs)
106+ Left (nearbyNames name (Map.keys pkgs))
107+
108+
109+nearbyNames :: Pkg.Name -> [Pkg.Name] -> [Pkg.Name]
110+nearbyNames (Pkg.Name author1 project1) possibleNames =
111+ let
112+ authorDist = authorDistance (Text.unpack author1)
113+ projectDist = projectDistance (Text.unpack project1)
114+
115+ addDistance name@(Pkg.Name author2 project2) =
116+ ( authorDist author2 + projectDist project2, name )
117+ in
118+ map snd $ take 4 $
119+ List.sortBy (compare `on` fst) $
120+ map addDistance possibleNames
121+
122+
123+authorDistance :: String -> Text.Text -> Int
124+authorDistance bad possibility =
125+ abs (Utils.distance bad (Text.unpack possibility))
126+
127+
128+projectDistance :: String -> Text.Text -> Int
129+projectDistance bad possibility =
130+ if possibility == "elm-lang" || possibility == "elm-explorations" then
131+ 0
132+ else
133+ abs (Utils.distance bad (Text.unpack possibility))
104
134
105
135
106
136
builder/src/Reporting/Exit.hs+12−9
@@ -136,17 +136,20 @@ toReport exit =
136
136
137 _:_ ->
137 _:_ ->
138 Help.report "OLD DEPENDENCIES" (Just "elm.json")
138 Help.report "OLD DEPENDENCIES" (Just "elm.json")
139− ( "You are using Elm " ++ Pkg.versionToString Compiler.version
139+ ( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
140− ++ ", but the following packages have not been updated for this version yet:"
141 )
140 )
142− [ P.vcat $ map (P.red . P.text . Pkg.toString) badPackages
141+ [ P.indent 4 $ P.vcat $ map (P.red . P.text . Pkg.toString) badPackages
142+ , Help.reflow $
143+ "This may be because it is not upgraded yet. It may be because a\
144+ \ better solution came along, so there was no need to upgrade it.\
145+ \ Etc. Try asking around on Slack to learn more about the topic."
143 , Help.note
146 , Help.note
144− "Please be kind to the relevant package authors! Having friendly interactions\
147+ "Whatever the case, please be kind to the relevant package authors! Having\
145− \ with users is great motivation, and conversely, getting berated by strangers\
148+ \ friendly interactions with users is great motivation, and conversely, getting\
146− \ on the internet sucks your soul dry. Furthermore, package authors are humans\
149+ \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
147− \ with families, friends, jobs, vacations, responsibilities, goals, etc. They\
150+ \ authors are humans with families, friends, jobs, vacations, responsibilities,\
148− \ face obstacles outside of their technical work you will never know about,\
151+ \ goals, etc. They face obstacles outside of their technical work you will never\
149− \ so please assume the best and try to be patient and supportive!"
152+ \ know about, so please assume the best and try to be patient and supportive!"
150 ]
153 ]
151
154
152 CannotMakeNothing ->
155 CannotMakeNothing ->
builder/src/Reporting/Exit/Deps.hs+1−39
@@ -6,9 +6,6 @@ module Reporting.Exit.Deps
6 where
6 where
7
7
8
8
9−import Data.Function (on)
10−import qualified Data.List as List
11−import qualified Data.Text as Text
12import Text.PrettyPrint.ANSI.Leijen ((<>))
9import Text.PrettyPrint.ANSI.Leijen ((<>))
13import qualified Text.PrettyPrint.ANSI.Leijen as P
10import qualified Text.PrettyPrint.ANSI.Leijen as P
14
11
@@ -51,11 +48,7 @@ toReport exit =
51 \ so you can delete it and see if that fixes the issue."
48 \ so you can delete it and see if that fixes the issue."
52 ]
49 ]
53
50
54− PackageNotFound package allPackages ->
51+ PackageNotFound package suggestions ->
55− let
56− suggestions =
57− nearbyNames package allPackages
58− in
59 Help.docReport "PACKAGE NOT FOUND" Nothing
52 Help.docReport "PACKAGE NOT FOUND" Nothing
60 ( P.fillSep
53 ( P.fillSep
61 ["I","cannot","find","a"
54 ["I","cannot","find","a"
@@ -111,34 +104,3 @@ toReport exit =
111 "This probably means the downloaded files got corrupted somehow.\
104 "This probably means the downloaded files got corrupted somehow.\
112 \ Maybe try deleting your ELM_HOME and see if that resolves the issue?"
105 \ Maybe try deleting your ELM_HOME and see if that resolves the issue?"
113 ]
106 ]
114−
115−
116−
117−-- NEARBY NAMES
118−
119−
120−nearbyNames :: Pkg.Name -> [Pkg.Name] -> [Pkg.Name]
121−nearbyNames (Pkg.Name author1 project1) possibleNames =
122− let
123− authorDist = authorDistance (Text.unpack author1)
124− projectDist = projectDistance (Text.unpack project1)
125−
126− addDistance name@(Pkg.Name author2 project2) =
127− ( authorDist author2 + projectDist project2, name )
128− in
129− map snd $ take 4 $
130− List.sortBy (compare `on` fst) $
131− map addDistance possibleNames
132−
133−
134−authorDistance :: String -> Text.Text -> Int
135−authorDistance bad possibility =
136− abs (Utils.distance bad (Text.unpack possibility))
137−
138−
139−projectDistance :: String -> Text.Text -> Int
140−projectDistance bad possibility =
141− if possibility == "elm-lang" || possibility == "elm-explorations" then
142− 0
143− else
144− abs (Utils.distance bad (Text.unpack possibility))
builder/src/Reporting/Exit/Diff.hs+4−16
@@ -38,24 +38,12 @@ toReport exit =
38
38
39 UnknownPackage pkg suggestions ->
39 UnknownPackage pkg suggestions ->
40 Help.report "UNKNOWN PACKAGE" Nothing
40 Help.report "UNKNOWN PACKAGE" Nothing
41− ( "You are trying to diff against this package:"
41+ ( "I cannot find a package called:"
42 )
42 )
43 [ P.indent 4 $ P.red $ P.text $ Pkg.toString pkg
43 [ P.indent 4 $ P.red $ P.text $ Pkg.toString pkg
44− , Help.stack $
45− case suggestions of
46− [] ->
47− [ "I cannot find that package though! Maybe there is a typo?"
48− ]
49−
50− [suggestion] ->
51− [ "I cannot find that package though! Maybe you want this one instead?"
52− , P.indent 4 $ P.dullyellow $ P.text (Pkg.toString suggestion)
53− ]
54−
55− _ ->
56− [ "I cannot find that package though! Maybe you want one of these instead?"
44+ , "Maybe you want one of these instead?"
57− , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
45+ , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
58− ]
46+ , "But check <https://package.elm-lang.org> to see all possibilities!"
59 ]
47 ]
60
48
61 UnknownVersion _pkg vsn realVersions ->
49 UnknownVersion _pkg vsn realVersions ->