on master help sign in
Make the "module not found" errors a bit nicer
commit2f4ea955a25bef8a0675af6b11ec4f304ac2859e authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 29 Mar 2018, 21:52 (9 years ago) parentd42572a
2 files changed+29−17
builder/src/File/Find.hs+2−2 builder/src/Reporting/Exit/Crawl.hs+27−15
builder/src/File/Find.hs+2−2
@@ -71,7 +71,7 @@ findElm srcDirs exposed origin name =
7171 return (Foreign pkg)
7272
7373 ([], Nothing) ->
74− Task.throw $ E.ModuleNotFound origin name
74+ Task.throw $ E.ModuleNotFound origin name srcDirs
7575
7676 (_, maybePkgs) ->
7777 Task.throw $ E.ModuleAmbiguous origin name paths (maybe [] id maybePkgs)
@@ -96,4 +96,4 @@ findKernel srcDir origin name =
9696 server <- liftIO $ Dir.doesFileExist serverPath
9797 if client
9898 then return $ Kernel clientPath (if server then Just serverPath else Nothing)
99− else Task.throw $ E.ModuleNotFound origin name
99+ else Task.throw $ E.ModuleNotFound origin name [srcDir]
builder/src/Reporting/Exit/Crawl.hs+27−15
@@ -36,7 +36,7 @@ data Exit
3636
3737
3838data Problem
39− = ModuleNotFound Origin Module.Raw -- TODO suggest other names
39+ = ModuleNotFound Origin Module.Raw [FilePath]
4040 | ModuleAmbiguous Origin Module.Raw [FilePath] [Pkg.Package]
4141 | BadHeader FilePath Time.UTCTime BS.ByteString Compiler.Error
4242 | ModuleNameReservedForKernel Origin Module.Raw
@@ -113,8 +113,8 @@ toReport exit =
113113problemToReport :: Problem -> Help.Report
114114problemToReport problem =
115115 case problem of
116− ModuleNotFound origin name ->
117− notFoundToDoc origin name
116+ ModuleNotFound origin name dirs ->
117+ notFoundToDoc origin name dirs
118118
119119 ModuleAmbiguous origin child paths pkgs ->
120120 ambiguousToDoc origin child paths pkgs
@@ -194,33 +194,34 @@ namelessToDoc path name =
194194 ]
195195
196196
197−notFoundToDoc :: Origin -> Module.Raw -> Help.Report
198−notFoundToDoc origin child =
197+notFoundToDoc :: Origin -> Module.Raw -> [FilePath] -> Help.Report
198+notFoundToDoc origin child dirs =
199199 case origin of
200200 ElmJson ->
201− Help.report "MODULE NOT FOUND" Nothing
201+ Help.report "MODULE NOT FOUND" (Just "elm.json")
202202 "Your elm.json says your project has the following module:"
203− [ P.indent 4 $ P.dullyellow $ P.text $ Module.nameToString child
203+ [ P.indent 4 $ P.red $ P.text $ Module.nameToString child
204204 , Help.reflow $
205− "I cannot find it though! Is there a typo in the module name?"
205+ "When creating packages, all modules must live in the\
206+ \ src/ directory, but I cannot find it there."
206207 ]
207208
208209 File path ->
209210 Help.report "UNKNOWN IMPORT" (Just path)
210211 ("I cannot find a `" ++ Module.nameToString child ++ "` module to import.")
211− (notFoundDetails child)
212+ (notFoundDetails child dirs)
212213
213214 Module path parent ->
214215 Help.report "UNKNOWN IMPORT" (Just path)
215216 ("The " ++ Module.nameToString parent ++ " module has a bad import:")
216− (notFoundDetails child)
217+ (notFoundDetails child dirs)
217218
218219
219−notFoundDetails :: Module.Raw -> [P.Doc]
220−notFoundDetails child =
220+notFoundDetails :: Module.Raw -> [FilePath] -> [P.Doc]
221+notFoundDetails child dirs =
221222 let
222223 simulatedCode =
223− P.indent 4 $ P.dullyellow $ P.text $ "import " ++ Module.nameToString child
224+ P.indent 4 $ P.red $ P.text $ "import " ++ Module.nameToString child
224225 in
225226 case Map.lookup child Pkg.suggestions of
226227 Just pkg ->
@@ -245,8 +246,19 @@ notFoundDetails child =
245246 ,"that","package","yet?"
246247 ]
247248 , Help.reflow $
248− "Is it a local file? Maybe it lives in some directory, but I cannot find that\
249− \ directory unless it is listed in the \"source-directories\" field of your elm.json!"
249+ case dirs of
250+ [] ->
251+ "Is it a local file? I look in directories listed in the \"source-directories\"\
252+ \ field of your elm.json, so maybe you need to add a \"src\" directory there?"
253+
254+ [dir] ->
255+ "Is it a local file? I look in directories listed in the \"source-directories\"\
256+ \ field of your elm.json, but it is not in the " ++ dir ++ " directory."
257+
258+ dir:_:_ ->
259+ "Is it a local file? I look in directories listed in the \"source-directories\"\
260+ \ field of your elm.json (like the " ++ dir ++ " directory) but I do not see it\
261+ \ in any of them."
250262 ]
251263 ]
252264