on master help sign in
Try to improve error messages in response to issue #479
50c2618Evan Czaplicki
compiler/Build/Dependencies.hs+30−22
@@ -29,10 +29,7 @@ getSortedDependencies srcDirs builtIns root =
29 result <- runErrorT $ readAllDeps allSrcDirs builtIns root
29 result <- runErrorT $ readAllDeps allSrcDirs builtIns root
30 case result of
30 case result of
31 Right deps -> sortDeps deps
31 Right deps -> sortDeps deps
32− Left err -> failure $ err ++ if Maybe.isJust extras then "" else msg
32+ Left err -> failure err
33− where msg = "\nYou may need to create a " ++
34− Path.dependencyFile ++
35− " file if you\nare trying to use a 3rd party library."
36
33
37extraDependencies :: IO (Maybe [FilePath])
34extraDependencies :: IO (Maybe [FilePath])
38extraDependencies =
35extraDependencies =
@@ -75,20 +72,22 @@ sortDeps depends =
75 msg = "A cyclical module dependency or was detected in:\n"
72 msg = "A cyclical module dependency or was detected in:\n"
76
73
77readAllDeps :: [FilePath] -> Module.Interfaces -> FilePath -> ErrorT String IO [Deps]
74readAllDeps :: [FilePath] -> Module.Interfaces -> FilePath -> ErrorT String IO [Deps]
78−readAllDeps srcDirs builtIns root =
75+readAllDeps srcDirs rawBuiltIns filePath =
79− do let ifaces = (Set.fromList . Map.keys) builtIns
80− State.evalStateT (go ifaces root) Set.empty
76+ State.evalStateT (go Nothing filePath) Set.empty
81 where
77 where
78+ builtIns :: Set.Set String
79+ builtIns = Set.fromList $ Map.keys rawBuiltIns
80+
82− go :: Set.Set String -> FilePath -> State.StateT (Set.Set String) (ErrorT String IO) [Deps]
81+ go :: Maybe String -> FilePath -> State.StateT (Set.Set String) (ErrorT String IO) [Deps]
83− go builtIns root = do
82+ go parentModuleName filePath = do
84− root' <- lift $ findSrcFile srcDirs root
83+ filePath' <- lift $ findSrcFile parentModuleName srcDirs filePath
85− (name, deps) <- lift $ readDeps root'
84+ (moduleName, deps) <- lift $ readDeps filePath'
86 seen <- State.get
85 seen <- State.get
87 let realDeps = Set.difference (Set.fromList deps) builtIns
86 let realDeps = Set.difference (Set.fromList deps) builtIns
88 newDeps = Set.difference (Set.filter (not . isNative) realDeps) seen
87 newDeps = Set.difference (Set.filter (not . isNative) realDeps) seen
89− State.put (Set.insert name (Set.union newDeps seen))
88+ State.put (Set.insert moduleName (Set.union newDeps seen))
90− rest <- mapM (go builtIns . toFilePath) (Set.toList newDeps)
89+ rest <- mapM (go (Just moduleName) . toFilePath) (Set.toList newDeps)
91− return ((makeRelative "." root', name, Set.toList realDeps) : concat rest)
90+ return ((makeRelative "." filePath', moduleName, Set.toList realDeps) : concat rest)
92
91
93readDeps :: FilePath -> ErrorT String IO (String, [String])
92readDeps :: FilePath -> ErrorT String IO (String, [String])
94readDeps path = do
93readDeps path = do
@@ -98,15 +97,10 @@ readDeps path = do
98 where msg = "Error resolving dependencies in " ++ path ++ ":\n"
97 where msg = "Error resolving dependencies in " ++ path ++ ":\n"
99 Right o -> return o
98 Right o -> return o
100
99
101−findSrcFile :: [FilePath] -> FilePath -> ErrorT String IO FilePath
100+findSrcFile :: Maybe String -> [FilePath] -> FilePath -> ErrorT String IO FilePath
101+findSrcFile parentModuleName dirs path =
102−findSrcFile dirs path = foldr tryDir notFound dirs
102+ foldr tryDir notFound dirs
103 where
103 where
104− notFound = throwError $ unlines
105− [ "Could not find file: " ++ path
106− , " If it is not in the root directory of your project, use"
107− , " --src-dir to declare additional locations for source files."
108− , " If it is part of a 3rd party library, it needs to be declared"
109− , " as a dependency in the " ++ Path.dependencyFile ++ " file." ]
110 tryDir dir next = do
104 tryDir dir next = do
111 let path' = dir </> path
105 let path' = dir </> path
112 exists <- liftIO $ doesFileExist path'
106 exists <- liftIO $ doesFileExist path'
@@ -114,6 +108,20 @@ findSrcFile dirs path = foldr tryDir notFound dirs
114 then return path'
108 then return path'
115 else next
109 else next
116
110
111+ parentModuleName' =
112+ case parentModuleName of
113+ Just name -> "module '" ++ name ++ "'"
114+ Nothing -> "the main module"
115+
116+ notFound = throwError $ unlines
117+ [ "When finding the imports declared in " ++ parentModuleName' ++ ", could not find file: " ++ path
118+ , " If you created this module, but it is in a subdirectory that does not"
119+ , " exactly match the module name, you may need to use the --src-dir flag."
120+ , ""
121+ , " If it is part of a 3rd party library, it needs to be declared"
122+ , " as a dependency in your project's " ++ Path.dependencyFile ++ " file."
123+ ]
124+
117isNative :: String -> Bool
125isNative :: String -> Bool
118isNative name = List.isPrefixOf "Native." name
126isNative name = List.isPrefixOf "Native." name
119
127
compiler/Transform/Canonicalize.hs+3−1
@@ -55,7 +55,9 @@ metadataModule :: Interfaces -> MetadataModule -> Either [Doc] MetadataModule
55metadataModule ifaces modul =
55metadataModule ifaces modul =
56 do case filter (\m -> Map.notMember m ifaces) (map fst realImports) of
56 do case filter (\m -> Map.notMember m ifaces) (map fst realImports) of
57 [] -> Right ()
57 [] -> Right ()
58− missings -> Left [ P.text $ "The following imports were not found: " ++ List.intercalate ", " missings ]
58+ missings -> Left [ P.text $ "The following imports were not found: " ++ List.intercalate ", " missings ++
59+ "\n You may need to compile with the --make flag to detect modules you have written."
60+ ]
59 program' <- rename initialEnv (program modul)
61 program' <- rename initialEnv (program modul)
60 aliases' <- mapM (three3 renameType') (aliases modul)
62 aliases' <- mapM (three3 renameType') (aliases modul)
61 datatypes' <- mapM (three3 (mapM (two2 (mapM renameType')))) (datatypes modul)
63 datatypes' <- mapM (three3 (mapM (two2 (mapM renameType')))) (datatypes modul)