on master help sign in
Show nicer error when module is not found in package
6f8ef99Evan Czaplicki
builder/src/File/Find.hs+11−6
@@ -45,7 +45,7 @@ find (Summary.Summary root project exposed _ _) origin name =
45 case project of
45 case project of
46 Project.App info ->
46 Project.App info ->
47 do let srcDirs = map toRoot (Project._app_source_dirs info)
47 do let srcDirs = map toRoot (Project._app_source_dirs info)
48− findElm srcDirs exposed origin name
48+ findElm project srcDirs exposed origin name
49
49
50 Project.Pkg _ ->
50 Project.Pkg _ ->
51 if N.startsWith "Elm.Kernel." name then
51 if N.startsWith "Elm.Kernel." name then
@@ -55,15 +55,15 @@ find (Summary.Summary root project exposed _ _) origin name =
55 Task.throw $ E.ModuleNameReservedForKernel origin name
55 Task.throw $ E.ModuleNameReservedForKernel origin name
56
56
57 else
57 else
58− findElm [ toRoot "src" ] exposed origin name
58+ findElm project [ toRoot "src" ] exposed origin name
59
59
60
60
61
61
62-- FIND ELM
62-- FIND ELM
63
63
64
64
65−findElm :: [FilePath] -> Summary.ExposedModules -> E.Origin -> Module.Raw -> Task.Task_ E.Problem Asset
65+findElm :: Project.Project -> [FilePath] -> Summary.ExposedModules -> E.Origin -> Module.Raw -> Task.Task_ E.Problem Asset
66−findElm srcDirs exposed origin name =
66+findElm project srcDirs exposed origin name =
67 do
67 do
68 paths <- liftIO $ Maybe.catMaybes <$> mapM (elmExists name) srcDirs
68 paths <- liftIO $ Maybe.catMaybes <$> mapM (elmExists name) srcDirs
69
69
@@ -75,7 +75,12 @@ findElm srcDirs exposed origin name =
75 return (Foreign pkg)
75 return (Foreign pkg)
76
76
77 ([], Nothing) ->
77 ([], Nothing) ->
78+ case project of
79+ Project.App _ ->
78− Task.throw $ E.ModuleNotFound origin name srcDirs
80+ Task.throw $ E.ModuleNotFound origin name (E.App srcDirs)
81+
82+ Project.Pkg _ ->
83+ Task.throw $ E.ModuleNotFound origin name E.Pkg
79
84
80 (_, maybePkgs) ->
85 (_, maybePkgs) ->
81 Task.throw $ E.ModuleAmbiguous origin name paths (maybe [] id maybePkgs)
86 Task.throw $ E.ModuleAmbiguous origin name paths (maybe [] id maybePkgs)
@@ -106,4 +111,4 @@ findKernel srcDir exposed origin name =
106 return ForeignKernel
111 return ForeignKernel
107
112
108 _ ->
113 _ ->
109− Task.throw $ E.ModuleNotFound origin name [srcDir]
114+ Task.throw $ E.ModuleNotFound origin name E.Pkg
builder/src/Reporting/Exit/Crawl.hs+40−20
@@ -3,6 +3,7 @@ module Reporting.Exit.Crawl
3 ( Exit(..)
3 ( Exit(..)
4 , Problem(..)
4 , Problem(..)
5 , Origin(..)
5 , Origin(..)
6+ , SrcDirs(..)
6 , toReport
7 , toReport
7 )
8 )
8 where
9 where
@@ -36,7 +37,7 @@ data Exit
36
37
37
38
38data Problem
39data Problem
39− = ModuleNotFound Origin Module.Raw [FilePath]
40+ = ModuleNotFound Origin Module.Raw SrcDirs
40 | ModuleAmbiguous Origin Module.Raw [FilePath] [Pkg.Package]
41 | ModuleAmbiguous Origin Module.Raw [FilePath] [Pkg.Package]
41 | BadHeader FilePath Time.UTCTime BS.ByteString Compiler.Error
42 | BadHeader FilePath Time.UTCTime BS.ByteString Compiler.Error
42 | ModuleNameReservedForKernel Origin Module.Raw
43 | ModuleNameReservedForKernel Origin Module.Raw
@@ -55,6 +56,11 @@ data Origin
55 | Module FilePath Module.Raw
56 | Module FilePath Module.Raw
56
57
57
58
59+data SrcDirs
60+ = App [FilePath]
61+ | Pkg
62+
63+
58
64
59-- TO REPORT
65-- TO REPORT
60
66
@@ -113,8 +119,8 @@ toReport exit =
113problemToReport :: Problem -> Help.Report
119problemToReport :: Problem -> Help.Report
114problemToReport problem =
120problemToReport problem =
115 case problem of
121 case problem of
116− ModuleNotFound origin name dirs ->
122+ ModuleNotFound origin name srcDirs ->
117− notFoundToDoc origin name dirs
123+ notFoundToDoc origin name srcDirs
118
124
119 ModuleAmbiguous origin child paths pkgs ->
125 ModuleAmbiguous origin child paths pkgs ->
120 ambiguousToDoc origin child paths pkgs
126 ambiguousToDoc origin child paths pkgs
@@ -173,7 +179,7 @@ badTagToDoc path name tag hintName summary =
173
179
174
180
175
181
176−-- HELPERS
182+-- NAMELESS
177
183
178
184
179namelessToDoc :: FilePath -> Module.Raw -> Help.Report
185namelessToDoc :: FilePath -> Module.Raw -> Help.Report
@@ -194,31 +200,34 @@ namelessToDoc path name =
194 ]
200 ]
195
201
196
202
203+
204+-- NOT FOUND
205+
206+
197−notFoundToDoc :: Origin -> Module.Raw -> [FilePath] -> Help.Report
207+notFoundToDoc :: Origin -> Module.Raw -> SrcDirs -> Help.Report
198−notFoundToDoc origin child dirs =
208+notFoundToDoc origin child srcDirs =
199 case origin of
209 case origin of
200 ElmJson ->
210 ElmJson ->
201 Help.report "MODULE NOT FOUND" (Just "elm.json")
211 Help.report "MODULE NOT FOUND" (Just "elm.json")
202 "Your elm.json says your project has the following module:"
212 "Your elm.json says your project has the following module:"
203 [ D.indent 4 $ D.red $ D.fromString $ Module.nameToString child
213 [ D.indent 4 $ D.red $ D.fromString $ Module.nameToString child
204 , D.reflow $
214 , D.reflow $
205− "When creating packages, all modules must live in the\
215+ "When creating packages, all modules must live in the src/ directory."
206− \ src/ directory, but I cannot find it there."
207 ]
216 ]
208
217
209 File path ->
218 File path ->
210 Help.report "UNKNOWN IMPORT" (Just path)
219 Help.report "UNKNOWN IMPORT" (Just path)
211 ("I cannot find a `" ++ Module.nameToString child ++ "` module to import.")
220 ("I cannot find a `" ++ Module.nameToString child ++ "` module to import.")
212− (notFoundDetails child dirs)
221+ (notFoundDetails child srcDirs)
213
222
214 Module path parent ->
223 Module path parent ->
215 Help.report "UNKNOWN IMPORT" (Just path)
224 Help.report "UNKNOWN IMPORT" (Just path)
216 ("The " ++ Module.nameToString parent ++ " module has a bad import:")
225 ("The " ++ Module.nameToString parent ++ " module has a bad import:")
217− (notFoundDetails child dirs)
226+ (notFoundDetails child srcDirs)
218
227
219
228
220−notFoundDetails :: Module.Raw -> [FilePath] -> [D.Doc]
229+notFoundDetails :: Module.Raw -> SrcDirs -> [D.Doc]
221−notFoundDetails child dirs =
230+notFoundDetails child srcDirs =
222 let
231 let
223 simulatedCode =
232 simulatedCode =
224 D.indent 4 $ D.red $ D.fromString $ "import " ++ Module.nameToString child
233 D.indent 4 $ D.red $ D.fromString $ "import " ++ Module.nameToString child
@@ -230,26 +239,37 @@ notFoundDetails child dirs =
230 "Do you want the one from the " ++ Pkg.toString pkg
239 "Do you want the one from the " ++ Pkg.toString pkg
231 ++ " package? If so, run this command to add that dependency to your elm.json file:"
240 ++ " package? If so, run this command to add that dependency to your elm.json file:"
232 , D.indent 4 $ D.green $ D.fromString $ "elm install " ++ Pkg.toString pkg
241 , D.indent 4 $ D.green $ D.fromString $ "elm install " ++ Pkg.toString pkg
242+ , case srcDirs of
243+ Pkg ->
233− , D.reflow $
244+ D.reflow $
234− "If you want a local file, make sure the directory that contains the `"
245+ "If you want a local file, make sure the `"
246+ ++ Module.nameToString child
247+ ++ "` module is in your src/ directory."
248+
249+ App _ ->
250+ D.reflow $
251+ "If you want a local file, make sure the `"
235− ++ Module.nameToString child
252+ ++ Module.nameToString child
236− ++ "` module is listed in your elm.json \"source-directories\" field."
253+ ++ "` module is in one of the \"source-directories\" listed in your elm.json file."
237 ]
254 ]
238
255
239 Nothing ->
256 Nothing ->
240 [ simulatedCode
257 [ simulatedCode
241 , "I cannot find that module! Is there a typo in the module name?"
258 , "I cannot find that module! Is there a typo in the module name?"
242 , D.reflow $
259 , D.reflow $
243− case dirs of
260+ case srcDirs of
261+ Pkg ->
262+ "When creating a package, all modules must live in the src/ directory."
263+
244− [] ->
264+ App [] ->
245 "The \"source-directories\" field of your elm.json is empty, so I only\
265 "The \"source-directories\" field of your elm.json is empty, so I only\
246 \ searched in packages. Maybe you need to add a \"src\" directory there?"
266 \ searched in packages. Maybe you need to add a \"src\" directory there?"
247
267
248− [dir] ->
268+ App [dir] ->
249 "The \"source-directories\" field of your elm.json tells me to only look in the "
269 "The \"source-directories\" field of your elm.json tells me to only look in the "
250 ++ dir ++ " directory, but it is not there. Maybe it is in a package that is not installed yet?"
270 ++ dir ++ " directory, but it is not there. Maybe it is in a package that is not installed yet?"
251
271
252− dir:_:_ ->
272+ App (dir:_:_) ->
253 "The \"source-directories\" field of your elm.json tells me to look in directories like "
273 "The \"source-directories\" field of your elm.json tells me to look in directories like "
254 ++ dir ++ ", but it is not in any of them. Maybe it is in a package that is not installed yet?"
274 ++ dir ++ ", but it is not in any of them. Maybe it is in a package that is not installed yet?"
255 ]
275 ]