on master help sign in
Improve some other error messages about unknown packages
commitd4e959918e42fc9be077cbc54e9b1de38f403c06 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 29 Mar 2018, 19:34 (9 years ago) parent988c63c
5 files changed+51−68
builder/src/Deps/Explorer.hs+3−3 builder/src/Deps/Get.hs+31−1 builder/src/Reporting/Exit.hs+12−9 builder/src/Reporting/Exit/Deps.hs+1−39 builder/src/Reporting/Exit/Diff.hs+4−16
builder/src/Deps/Explorer.hs+3−3
@@ -73,8 +73,8 @@ exists name =
7373 Right _ ->
7474 return ()
7575
76− Left allPkgs ->
77− throwError (Exit.Deps (E.PackageNotFound name allPkgs))
76+ Left suggestions ->
77+ throwError (Exit.Deps (E.PackageNotFound name suggestions))
7878
7979
8080
@@ -88,7 +88,7 @@ getVersions name =
8888 Right versions ->
8989 return versions
9090
91− Left _allPkgs ->
91+ Left _suggestions ->
9292 throwError (Exit.Deps (E.CorruptVersionCache name))
9393
9494
builder/src/Deps/Get.hs+31−1
@@ -14,15 +14,18 @@ module Deps.Get
1414import Prelude hiding (all)
1515import Control.Monad.Except (catchError, liftIO)
1616import qualified Data.ByteString as BS
17+import Data.Function (on)
1718import qualified Data.List as List
1819import qualified Data.Map as Map
1920import Data.Map (Map)
21+import qualified Data.Text as Text
2022import qualified System.Directory as Dir
2123import System.FilePath ((</>))
2224import qualified Text.PrettyPrint.ANSI.Leijen as P
2325
2426import qualified Elm.Docs as Docs
2527import qualified Elm.Package as Pkg
28+import qualified Elm.Utils as Utils
2629
2730import qualified Deps.Website as Website
2831import qualified Elm.Project.Json as Project
@@ -100,7 +103,34 @@ versions name (AllPackages pkgs) =
100103 Right vsns
101104
102105 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))
104134
105135
106136
builder/src/Reporting/Exit.hs+12−9
@@ -136,17 +136,20 @@ toReport exit =
136136
137137 _:_ ->
138138 Help.report "OLD DEPENDENCIES" (Just "elm.json")
139− ( "You are using Elm " ++ Pkg.versionToString Compiler.version
140− ++ ", but the following packages have not been updated for this version yet:"
139+ ( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
141140 )
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."
143146 , Help.note
144− "Please be kind to the relevant package authors! Having friendly interactions\
145− \ with users is great motivation, and conversely, getting berated by strangers\
146− \ on the internet sucks your soul dry. Furthermore, package authors are humans\
147− \ with families, friends, jobs, vacations, responsibilities, goals, etc. They\
148− \ face obstacles outside of their technical work you will never know about,\
149− \ so please assume the best and try to be patient and supportive!"
147+ "Whatever the case, please be kind to the relevant package authors! Having\
148+ \ friendly interactions with users is great motivation, and conversely, getting\
149+ \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
150+ \ authors are humans with families, friends, jobs, vacations, responsibilities,\
151+ \ goals, etc. They face obstacles outside of their technical work you will never\
152+ \ know about, so please assume the best and try to be patient and supportive!"
150153 ]
151154
152155 CannotMakeNothing ->
builder/src/Reporting/Exit/Deps.hs+1−39
@@ -6,9 +6,6 @@ module Reporting.Exit.Deps
66 where
77
88
9−import Data.Function (on)
10−import qualified Data.List as List
11−import qualified Data.Text as Text
129import Text.PrettyPrint.ANSI.Leijen ((<>))
1310import qualified Text.PrettyPrint.ANSI.Leijen as P
1411
@@ -51,11 +48,7 @@ toReport exit =
5148 \ so you can delete it and see if that fixes the issue."
5249 ]
5350
54− PackageNotFound package allPackages ->
55− let
56− suggestions =
57− nearbyNames package allPackages
58− in
51+ PackageNotFound package suggestions ->
5952 Help.docReport "PACKAGE NOT FOUND" Nothing
6053 ( P.fillSep
6154 ["I","cannot","find","a"
@@ -111,34 +104,3 @@ toReport exit =
111104 "This probably means the downloaded files got corrupted somehow.\
112105 \ Maybe try deleting your ELM_HOME and see if that resolves the issue?"
113106 ]
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 =
3838
3939 UnknownPackage pkg suggestions ->
4040 Help.report "UNKNOWN PACKAGE" Nothing
41− ( "You are trying to diff against this package:"
41+ ( "I cannot find a package called:"
4242 )
4343 [ 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?"
57− , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
58− ]
44+ , "Maybe you want one of these instead?"
45+ , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
46+ , "But check <https://package.elm-lang.org> to see all possibilities!"
5947 ]
6048
6149 UnknownVersion _pkg vsn realVersions ->