on master help sign in
Improve the error message for "UNKNOWN MODULE"
commit33efdcfd9054f3b49fa4f32b5ce5109cc884449e authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 2 Apr 2018, 17:28 (9 years ago) parent8a68814
2 files changed+30−35
builder/src/File/Find.hs+17−14 builder/src/Reporting/Exit/Crawl.hs+13−21
builder/src/File/Find.hs+17−14
@@ -9,6 +9,7 @@ module File.Find
99import Control.Monad.Except (liftIO)
1010import qualified Data.Map as Map
1111import qualified Data.Maybe as Maybe
12+import qualified System.FilePath as FP
1213import qualified System.Directory as Dir
1314import System.FilePath ((</>), (<.>))
1415
@@ -38,20 +39,22 @@ data Asset
3839
3940find :: Summary.Summary -> E.Origin -> Module.Raw -> Task.Task_ E.Problem Asset
4041find (Summary.Summary root project exposed _ _) origin name =
41− case project of
42− Project.App info ->
43− do let srcDirs = map (root </>) (Project._app_source_dirs info)
44− findElm srcDirs exposed origin name
45−
46− Project.Pkg _ ->
47− if N.startsWith "Elm.Kernel." name then
48− if Project.isPlatformPackage project then
49− findKernel (root </> "src") origin name
50− else
51− Task.throw $ E.ModuleNameReservedForKernel origin name
52−
53− else
54− findElm [ root </> "src" ] exposed origin name
42+ do here <- liftIO Dir.getCurrentDirectory
43+ let toRoot dir = FP.makeRelative here (root </> dir)
44+ case project of
45+ Project.App info ->
46+ do let srcDirs = map toRoot (Project._app_source_dirs info)
47+ findElm srcDirs exposed origin name
48+
49+ Project.Pkg _ ->
50+ if N.startsWith "Elm.Kernel." name then
51+ if Project.isPlatformPackage project then
52+ findKernel (toRoot "src") origin name
53+ else
54+ Task.throw $ E.ModuleNameReservedForKernel origin name
55+
56+ else
57+ findElm [ toRoot "src" ] exposed origin name
5558
5659
5760
builder/src/Reporting/Exit/Crawl.hs+13−21
@@ -239,27 +239,19 @@ notFoundDetails child dirs =
239239 Nothing ->
240240 [ simulatedCode
241241 , "I cannot find that module! Is there a typo in the module name?"
242− , P.vcat
243− [ P.fillSep
244− ["Is","it","defined","in","a","package?","Did","you"
245− ,P.green "elm install"
246− ,"that","package","yet?"
247− ]
248− , Help.reflow $
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."
262− ]
242+ , Help.reflow $
243+ case dirs of
244+ [] ->
245+ "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?"
247+
248+ [dir] ->
249+ "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?"
251+
252+ dir:_:_ ->
253+ "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?"
263255 ]
264256
265257