on master help sign in
Make the "module not found" errors a bit nicer
2f4ea95Evan Czaplicki
builder/src/File/Find.hs+2−2
@@ -71,7 +71,7 @@ findElm srcDirs exposed origin name =
71 return (Foreign pkg)
71 return (Foreign pkg)
72
72
73 ([], Nothing) ->
73 ([], Nothing) ->
74− Task.throw $ E.ModuleNotFound origin name
74+ Task.throw $ E.ModuleNotFound origin name srcDirs
75
75
76 (_, maybePkgs) ->
76 (_, maybePkgs) ->
77 Task.throw $ E.ModuleAmbiguous origin name paths (maybe [] id maybePkgs)
77 Task.throw $ E.ModuleAmbiguous origin name paths (maybe [] id maybePkgs)
@@ -96,4 +96,4 @@ findKernel srcDir origin name =
96 server <- liftIO $ Dir.doesFileExist serverPath
96 server <- liftIO $ Dir.doesFileExist serverPath
97 if client
97 if client
98 then return $ Kernel clientPath (if server then Just serverPath else Nothing)
98 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
36
36
37
37
38data Problem
38data Problem
39− = ModuleNotFound Origin Module.Raw -- TODO suggest other names
39+ = ModuleNotFound Origin Module.Raw [FilePath]
40 | ModuleAmbiguous Origin Module.Raw [FilePath] [Pkg.Package]
40 | ModuleAmbiguous Origin Module.Raw [FilePath] [Pkg.Package]
41 | BadHeader FilePath Time.UTCTime BS.ByteString Compiler.Error
41 | BadHeader FilePath Time.UTCTime BS.ByteString Compiler.Error
42 | ModuleNameReservedForKernel Origin Module.Raw
42 | ModuleNameReservedForKernel Origin Module.Raw
@@ -113,8 +113,8 @@ toReport exit =
113problemToReport :: Problem -> Help.Report
113problemToReport :: Problem -> Help.Report
114problemToReport problem =
114problemToReport problem =
115 case problem of
115 case problem of
116− ModuleNotFound origin name ->
116+ ModuleNotFound origin name dirs ->
117− notFoundToDoc origin name
117+ notFoundToDoc origin name dirs
118
118
119 ModuleAmbiguous origin child paths pkgs ->
119 ModuleAmbiguous origin child paths pkgs ->
120 ambiguousToDoc origin child paths pkgs
120 ambiguousToDoc origin child paths pkgs
@@ -194,33 +194,34 @@ namelessToDoc path name =
194 ]
194 ]
195
195
196
196
197−notFoundToDoc :: Origin -> Module.Raw -> Help.Report
197+notFoundToDoc :: Origin -> Module.Raw -> [FilePath] -> Help.Report
198−notFoundToDoc origin child =
198+notFoundToDoc origin child dirs =
199 case origin of
199 case origin of
200 ElmJson ->
200 ElmJson ->
201− Help.report "MODULE NOT FOUND" Nothing
201+ Help.report "MODULE NOT FOUND" (Just "elm.json")
202 "Your elm.json says your project has the following module:"
202 "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
204 , Help.reflow $
204 , Help.reflow $
205+ "When creating packages, all modules must live in the\
205− "I cannot find it though! Is there a typo in the module name?"
206+ \ src/ directory, but I cannot find it there."
206 ]
207 ]
207
208
208 File path ->
209 File path ->
209 Help.report "UNKNOWN IMPORT" (Just path)
210 Help.report "UNKNOWN IMPORT" (Just path)
210 ("I cannot find a `" ++ Module.nameToString child ++ "` module to import.")
211 ("I cannot find a `" ++ Module.nameToString child ++ "` module to import.")
211− (notFoundDetails child)
212+ (notFoundDetails child dirs)
212
213
213 Module path parent ->
214 Module path parent ->
214 Help.report "UNKNOWN IMPORT" (Just path)
215 Help.report "UNKNOWN IMPORT" (Just path)
215 ("The " ++ Module.nameToString parent ++ " module has a bad import:")
216 ("The " ++ Module.nameToString parent ++ " module has a bad import:")
216− (notFoundDetails child)
217+ (notFoundDetails child dirs)
217
218
218
219
219−notFoundDetails :: Module.Raw -> [P.Doc]
220+notFoundDetails :: Module.Raw -> [FilePath] -> [P.Doc]
220−notFoundDetails child =
221+notFoundDetails child dirs =
221 let
222 let
222 simulatedCode =
223 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
224 in
225 in
225 case Map.lookup child Pkg.suggestions of
226 case Map.lookup child Pkg.suggestions of
226 Just pkg ->
227 Just pkg ->
@@ -245,8 +246,19 @@ notFoundDetails child =
245 ,"that","package","yet?"
246 ,"that","package","yet?"
246 ]
247 ]
247 , Help.reflow $
248 , Help.reflow $
248− "Is it a local file? Maybe it lives in some directory, but I cannot find that\
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:_:_ ->
249− \ directory unless it is listed in the \"source-directories\" field of your elm.json!"
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."
250 ]
262 ]
251 ]
263 ]
252
264