on master help sign in
Track more information with Reporting.Error.Import
7b60982Evan Czaplicki
builder/src/Build.hs+122−88
@@ -1,5 +1,5 @@
1{-# OPTIONS_GHC -Wno-unused-do-bind #-}
1{-# OPTIONS_GHC -Wno-unused-do-bind #-}
2−{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE BangPatterns, OverloadedStrings #-}
3module Build
3module Build
4 ( fromExposed
4 ( fromExposed
5 , fromMains
5 , fromMains
@@ -26,6 +26,7 @@ import qualified Data.Maybe as Maybe
26import qualified Data.Name as Name
26import qualified Data.Name as Name
27import qualified Data.NonEmptyList as NE
27import qualified Data.NonEmptyList as NE
28import qualified Data.OneOrMore as OneOrMore
28import qualified Data.OneOrMore as OneOrMore
29+import qualified Data.Set as Set
29import qualified System.Directory as Dir
30import qualified System.Directory as Dir
30import qualified System.FilePath as FP
31import qualified System.FilePath as FP
31import System.FilePath ((</>), (<.>))
32import System.FilePath ((</>), (<.>))
@@ -42,9 +43,10 @@ import qualified File
42import qualified Parse.Module as Parse
43import qualified Parse.Module as Parse
43import qualified Reporting
44import qualified Reporting
44import qualified Reporting.Annotation as A
45import qualified Reporting.Annotation as A
46+import qualified Reporting.Error as Error
47+import qualified Reporting.Error.Syntax as Syntax
48+import qualified Reporting.Error.Import as Import
45import qualified Reporting.Exit as Exit
49import qualified Reporting.Exit as Exit
46−import qualified Reporting.Problem as Problem
47−import qualified Reporting.Render.Type.Localizer as Localizer
48import qualified Stuff
50import qualified Stuff
49
51
50
52
@@ -172,7 +174,7 @@ fromMains style root details paths =
172 rmvar <- newEmptyMVar
174 rmvar <- newEmptyMVar
173 resultsMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
175 resultsMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
174 putMVar rmvar resultsMVars
176 putMVar rmvar resultsMVars
175− rmainMVars <- traverse (fork . checkMain env resultsMVars) smains
177+ rmainMVars <- traverse (fork . checkMain env foreigns resultsMVars) smains
176 results <- traverse readMVar resultsMVars
178 results <- traverse readMVar resultsMVars
177 writeDetails root details results
179 writeDetails root details results
178 toArtifacts env foreigns results <$> traverse readMVar rmainMVars
180 toArtifacts env foreigns results <$> traverse readMVar rmainMVars
@@ -189,8 +191,8 @@ type StatusDict =
189data Status
191data Status
190 = SCached Details.Local
192 = SCached Details.Local
191 | SChanged Details.Local B.ByteString Src.Module
193 | SChanged Details.Local B.ByteString Src.Module
192− | SBadImport Problem.Import
194+ | SBadImport Import.Problem
193− | SBadSyntax Problem.Syntax
195+ | SBadSyntax FilePath File.Time B.ByteString Syntax.Error
194 | SForeign Pkg.Name
196 | SForeign Pkg.Name
195 | SKernel
197 | SKernel
196
198
@@ -219,7 +221,7 @@ crawlModule env@(Env _ root pkg srcDirs locals foreigns) mvar name =
219 [path] ->
221 [path] ->
220 case Map.lookup name foreigns of
222 case Map.lookup name foreigns of
221 Just (Details.Foreign dep deps) ->
223 Just (Details.Foreign dep deps) ->
222− return $ SBadImport $ Import.Ambiguous name path [] dep deps
224+ return $ SBadImport $ Import.Ambiguous path [] dep deps
223
225
224 Nothing ->
226 Nothing ->
225 case Map.lookup name locals of
227 case Map.lookup name locals of
@@ -236,7 +238,7 @@ crawlModule env@(Env _ root pkg srcDirs locals foreigns) mvar name =
236 else crawlDeps env mvar deps (SCached local)
238 else crawlDeps env mvar deps (SCached local)
237
239
238 p1:p2:ps ->
240 p1:p2:ps ->
239− return $ SBadImport $ Import.AmbiguousLocal name p1 p2 ps
241+ return $ SBadImport $ Import.AmbiguousLocal p1 p2 ps
240
242
241 [] ->
243 [] ->
242 case Map.lookup name foreigns of
244 case Map.lookup name foreigns of
@@ -246,14 +248,14 @@ crawlModule env@(Env _ root pkg srcDirs locals foreigns) mvar name =
246 return $ SForeign dep
248 return $ SForeign dep
247
249
248 d:ds ->
250 d:ds ->
249− return $ SBadImport $ Import.AmbiguousForeign name dep d ds
251+ return $ SBadImport $ Import.AmbiguousForeign dep d ds
250
252
251 Nothing ->
253 Nothing ->
252 if Name.isKernel name && Pkg.isKernel pkg then
254 if Name.isKernel name && Pkg.isKernel pkg then
253 do exists <- File.exists ("src" </> ModuleName.toFilePath name <.> "js")
255 do exists <- File.exists ("src" </> ModuleName.toFilePath name <.> "js")
254− return $ if exists then SKernel else SBadImport (Import.NotFound name)
256+ return $ if exists then SKernel else SBadImport Import.NotFound
255 else
257 else
256− return $ SBadImport (Import.NotFound name)
258+ return $ SBadImport Import.NotFound
257
259
258
260
259crawlFile :: Env -> MVar StatusDict -> ModuleName.Raw -> FilePath -> IO Status
261crawlFile :: Env -> MVar StatusDict -> ModuleName.Raw -> FilePath -> IO Status
@@ -262,9 +264,15 @@ crawlFile env@(Env _ root pkg _ _ _) mvar expectedName path =
262 source <- File.readUtf8 (root </> path)
264 source <- File.readUtf8 (root </> path)
263
265
264 case Parse.fromByteString pkg source of
266 case Parse.fromByteString pkg source of
267+ Left err ->
268+ return $ SBadSyntax path time source err
269+
265 Right modul@(Src.Module maybeActualName _ imports values _ _ _ _) ->
270 Right modul@(Src.Module maybeActualName _ imports values _ _ _ _) ->
266 case maybeActualName of
271 case maybeActualName of
272+ Nothing ->
273+ return $ SBadSyntax path time source (Syntax.ModuleNameUnspecified expectedName)
274+
267− Just actualName ->
275+ Just name@(A.At _ actualName) ->
268 if expectedName == actualName then
276 if expectedName == actualName then
269 let
277 let
270 deps = map Src.getImportName imports
278 deps = map Src.getImportName imports
@@ -272,13 +280,7 @@ crawlFile env@(Env _ root pkg _ _ _) mvar expectedName path =
272 in
280 in
273 crawlDeps env mvar deps (SChanged local source modul)
281 crawlDeps env mvar deps (SChanged local source modul)
274 else
282 else
275− return $ SBadSyntax $ Problem.ModuleNameMismatch expectedName actualName
283+ return $ SBadSyntax path time source (Syntax.ModuleNameMismatch expectedName name)
276−
277− Nothing ->
278− return $ SBadSyntax $ Problem.ModuleNameUnspecified expectedName
279−
280− Left syntaxError ->
281− return $ SBadSyntax $ Problem.SyntaxProblem path time syntaxError
282
284
283
285
284isMain :: A.Located Src.Value -> Bool
286isMain :: A.Located Src.Value -> Bool
@@ -298,8 +300,8 @@ data Result
298 = RNew Details.Local I.Interface Opt.LocalGraph
300 = RNew Details.Local I.Interface Opt.LocalGraph
299 | RSame Details.Local I.Interface Opt.LocalGraph
301 | RSame Details.Local I.Interface Opt.LocalGraph
300 | RCached Bool (MVar CachedInterface)
302 | RCached Bool (MVar CachedInterface)
301− | RNotFound Problem.Import
303+ | RNotFound Import.Problem
302− | RProblem Problem.Problem
304+ | RProblem Error.Module
303 | RBlocked
305 | RBlocked
304 | RForeign I.Interface
306 | RForeign I.Interface
305 | RKernel
307 | RKernel
@@ -322,9 +324,9 @@ checkModule env@(Env _ root pkg _ _ _) foreigns resultsMVar name status =
322 do source <- File.readUtf8 path
324 do source <- File.readUtf8 path
323 case Parse.fromByteString pkg source of
325 case Parse.fromByteString pkg source of
324 Right modul -> compile env local source ifaces modul
326 Right modul -> compile env local source ifaces modul
325− Left syntaxError ->
327+ Left err ->
326− return $ RProblem $ Problem.BadSyntax $
328+ return $ RProblem $
327− Problem.SyntaxProblem path time syntaxError
329+ Error.Module name path time source (Error.BadSyntax err)
328
330
329 DepsSame _ _ ->
331 DepsSame _ _ ->
330 do mvar <- newMVar Unneeded
332 do mvar <- newMVar Unneeded
@@ -333,10 +335,17 @@ checkModule env@(Env _ root pkg _ _ _) foreigns resultsMVar name status =
333 DepsBlock ->
335 DepsBlock ->
334 return RBlocked
336 return RBlocked
335
337
336− DepsNotFound name1 problem1 others ->
338+ DepsNotFound problems ->
337− return (RProblem (Problem.BadImports name1 problem1 others))
339+ do source <- File.readUtf8 path
340+ return $ RProblem $ Error.Module name path time source $
341+ case Parse.fromByteString pkg source of
342+ Right (Src.Module _ _ imports _ _ _ _ _) ->
343+ Error.BadImports (toImportErrors foreigns results imports problems)
344+
345+ Left err ->
346+ Error.BadSyntax err
338
347
339− SChanged local@(Details.Local _ _ deps _) source modul ->
348+ SChanged local@(Details.Local path time deps _) source modul@(Src.Module _ _ imports _ _ _ _ _) ->
340 do results <- readMVar resultsMVar
349 do results <- readMVar resultsMVar
341 depsStatus <- checkDeps root results deps
350 depsStatus <- checkDeps root results deps
342 case depsStatus of
351 case depsStatus of
@@ -356,14 +365,16 @@ checkModule env@(Env _ root pkg _ _ _) foreigns resultsMVar name status =
356 DepsBlock ->
365 DepsBlock ->
357 return RBlocked
366 return RBlocked
358
367
359− DepsNotFound name1 problem1 others ->
368+ DepsNotFound problems ->
360− return (RProblem (Problem.BadImports name1 problem1 others))
369+ return $ RProblem $ Error.Module name path time source $
370+ Error.BadImports (toImportErrors foreigns results imports problems)
361
371
362 SBadImport importProblem ->
372 SBadImport importProblem ->
363 return (RNotFound importProblem)
373 return (RNotFound importProblem)
364
374
365− SBadSyntax syntaxProblem ->
375+ SBadSyntax path time source err ->
366− return (RProblem (Problem.BadSyntax syntaxProblem))
376+ return $ RProblem $ Error.Module name path time source $
377+ Error.BadSyntax err
367
378
368 SForeign home ->
379 SForeign home ->
369 case foreigns ! ModuleName.Canonical home name of
380 case foreigns ! ModuleName.Canonical home name of
@@ -382,7 +393,7 @@ data DepsStatus
382 = DepsChange (Map.Map ModuleName.Raw I.Interface)
393 = DepsChange (Map.Map ModuleName.Raw I.Interface)
383 | DepsSame [Dep] [CDep]
394 | DepsSame [Dep] [CDep]
384 | DepsBlock
395 | DepsBlock
385− | DepsNotFound ModuleName.Raw Problem.Import [(ModuleName.Raw, Problem.Import)]
396+ | DepsNotFound (NE.List (ModuleName.Raw, Import.Problem))
386
397
387
398
388checkDeps :: FilePath -> ResultDict -> [ModuleName.Raw] -> IO DepsStatus
399checkDeps :: FilePath -> ResultDict -> [ModuleName.Raw] -> IO DepsStatus
@@ -394,25 +405,25 @@ type Dep = (ModuleName.Raw, I.Interface)
394type CDep = (ModuleName.Raw, MVar CachedInterface)
405type CDep = (ModuleName.Raw, MVar CachedInterface)
395
406
396
407
397−checkDepsHelp :: FilePath -> ResultDict -> [ModuleName.Raw] -> [Dep] -> [Dep] -> [CDep] -> [(ModuleName.Raw, Problem.Import)] -> Bool -> IO DepsStatus
408+checkDepsHelp :: FilePath -> ResultDict -> [ModuleName.Raw] -> [Dep] -> [Dep] -> [CDep] -> [(ModuleName.Raw,Import.Problem)] -> Bool -> IO DepsStatus
398−checkDepsHelp root results deps new same cached badImports isBlocked =
409+checkDepsHelp root results deps new same cached importProblems isBlocked =
399 case deps of
410 case deps of
400 dep:otherDeps ->
411 dep:otherDeps ->
401 do result <- readMVar (results ! dep)
412 do result <- readMVar (results ! dep)
402 case result of
413 case result of
403− RNew _ iface _ -> checkDepsHelp root results otherDeps ((dep,iface) : new) same cached badImports isBlocked
414+ RNew _ iface _ -> checkDepsHelp root results otherDeps ((dep,iface) : new) same cached importProblems isBlocked
404− RSame _ iface _ -> checkDepsHelp root results otherDeps new ((dep,iface) : same) cached badImports isBlocked
415+ RSame _ iface _ -> checkDepsHelp root results otherDeps new ((dep,iface) : same) cached importProblems isBlocked
405− RCached _ mvar -> checkDepsHelp root results otherDeps new same ((dep,mvar) : cached) badImports isBlocked
416+ RCached _ mvar -> checkDepsHelp root results otherDeps new same ((dep,mvar) : cached) importProblems isBlocked
406− RNotFound prob -> checkDepsHelp root results otherDeps new same cached ((dep,prob) : badImports) True
417+ RNotFound prob -> checkDepsHelp root results otherDeps new same cached ((dep,prob) : importProblems) True
407− RProblem _ -> checkDepsHelp root results otherDeps new same cached badImports True
418+ RProblem _ -> checkDepsHelp root results otherDeps new same cached importProblems True
408− RBlocked -> checkDepsHelp root results otherDeps new same cached badImports True
419+ RBlocked -> checkDepsHelp root results otherDeps new same cached importProblems True
409− RForeign iface -> checkDepsHelp root results otherDeps new ((dep,iface) : same) cached badImports isBlocked
420+ RForeign iface -> checkDepsHelp root results otherDeps new ((dep,iface) : same) cached importProblems isBlocked
410− RKernel -> checkDepsHelp root results otherDeps new same cached badImports isBlocked
421+ RKernel -> checkDepsHelp root results otherDeps new same cached importProblems isBlocked
411
422
412 [] ->
423 [] ->
413− case badImports of
424+ case importProblems of
414− (name, problem) : otherBadImports ->
425+ p:ps ->
415− return $ DepsNotFound name problem otherBadImports
426+ return $ DepsNotFound (NE.List p ps)
416
427
417 [] ->
428 [] ->
418 if isBlocked then
429 if isBlocked then
@@ -433,6 +444,27 @@ checkDepsHelp root results deps new same cached badImports isBlocked =
433
444
434
445
435
446
447+-- TO IMPORT ERROR
448+
449+
450+toImportErrors :: Dependencies -> ResultDict -> [Src.Import] -> NE.List (ModuleName.Raw, Import.Problem) -> NE.List Import.Error
451+toImportErrors foreigns results imports problems =
452+ let
453+ knownModules =
454+ Set.union
455+ (Set.fromList (map ModuleName._module (Map.keys foreigns)))
456+ (Map.keysSet results)
457+
458+ regionDict =
459+ Map.fromList (map (\(Src.Import (A.At region name) _ _) -> (name, region)) imports)
460+
461+ toError (name, problem) =
462+ Import.Error (regionDict ! name) name knownModules problem
463+ in
464+ fmap toError problems
465+
466+
467+
436-- CACHED INTERFACE
468-- CACHED INTERFACE
437
469
438
470
@@ -543,7 +575,7 @@ addToGraph name status graph =
543 SCached (Details.Local _ _ deps _) -> deps
575 SCached (Details.Local _ _ deps _) -> deps
544 SChanged (Details.Local _ _ deps _) _ _ -> deps
576 SChanged (Details.Local _ _ deps _) _ _ -> deps
545 SBadImport _ -> []
577 SBadImport _ -> []
546− SBadSyntax _ -> []
578+ SBadSyntax _ _ _ _ -> []
547 SForeign _ -> []
579 SForeign _ -> []
548 SKernel -> []
580 SKernel -> []
549 in
581 in
@@ -591,7 +623,7 @@ checkInside name p1 status =
591 SCached (Details.Local p2 _ _ _) -> Left (Exit.BP_MainNameDuplicate name p1 p2)
623 SCached (Details.Local p2 _ _ _) -> Left (Exit.BP_MainNameDuplicate name p1 p2)
592 SChanged (Details.Local p2 _ _ _) _ _ -> Left (Exit.BP_MainNameDuplicate name p1 p2)
624 SChanged (Details.Local p2 _ _ _) _ _ -> Left (Exit.BP_MainNameDuplicate name p1 p2)
593 SBadImport _ -> Right ()
625 SBadImport _ -> Right ()
594− SBadSyntax _ -> Right ()
626+ SBadSyntax _ _ _ _ -> Right ()
595 SForeign _ -> Right ()
627 SForeign _ -> Right ()
596 SKernel -> Right ()
628 SKernel -> Right ()
597
629
@@ -621,10 +653,10 @@ compile (Env key root pkg _ _ _) local@(Details.Local path time _ _) source ifac
621 Reporting.report key Reporting.BDone
653 Reporting.report key Reporting.BDone
622 return (RNew local iface objects)
654 return (RNew local iface objects)
623
655
624− Left errors ->
656+ Left err ->
625 do Reporting.report key Reporting.BDone
657 do Reporting.report key Reporting.BDone
626− return $ RProblem $ Problem.BadContent $
658+ return $ RProblem $
627− Problem.Module (Src.getName modul) path time source errors (Localizer.fromModule modul)
659+ Error.Module (Src.getName modul) path time source err
628
660
629
661
630
662
@@ -656,22 +688,22 @@ addNewLocal name result locals =
656
688
657detectProblems :: Map.Map ModuleName.Raw Result -> Either Exit.BuildProblem ()
689detectProblems :: Map.Map ModuleName.Raw Result -> Either Exit.BuildProblem ()
658detectProblems results =
690detectProblems results =
659− case Map.foldr addProblem [] results of
691+ case Map.foldr addErrors [] results of
660 [] -> Right ()
692 [] -> Right ()
661− p:ps -> Left (Exit.BuildModuleProblems p ps)
693+ e:es -> Left (Exit.BuildModuleProblems e es)
662
694
663
695
664−addProblem :: Result -> [Problem.Problem] -> [Problem.Problem]
696+addErrors :: Result -> [Error.Module] -> [Error.Module]
665−addProblem result problems =
697+addErrors result errors =
666 case result of
698 case result of
667− RNew _ _ _ -> problems
699+ RNew _ _ _ -> errors
668− RSame _ _ _ -> problems
700+ RSame _ _ _ -> errors
669− RCached _ _ -> problems
701+ RCached _ _ -> errors
670− RNotFound _ -> problems
702+ RNotFound _ -> errors
671− RProblem p -> p:problems
703+ RProblem e -> e:errors
672− RBlocked -> problems
704+ RBlocked -> errors
673− RForeign _ -> problems
705+ RForeign _ -> errors
674− RKernel -> problems
706+ RKernel -> errors
675
707
676
708
677
709
@@ -804,7 +836,7 @@ dropPrefix roots paths =
804data MainStatus
836data MainStatus
805 = SInside ModuleName.Raw
837 = SInside ModuleName.Raw
806 | SOutsideOk Details.Local B.ByteString Src.Module
838 | SOutsideOk Details.Local B.ByteString Src.Module
807− | SOutsideErr Problem.Syntax
839+ | SOutsideErr Error.Module
808
840
809
841
810crawlMain :: Env -> MVar StatusDict -> MainLocation -> IO MainStatus
842crawlMain :: Env -> MVar StatusDict -> MainLocation -> IO MainStatus
@@ -827,7 +859,8 @@ crawlMain env@(Env _ _ pkg _ _ _) mvar given =
827 crawlDeps env mvar deps (SOutsideOk local source modul)
859 crawlDeps env mvar deps (SOutsideOk local source modul)
828
860
829 Left syntaxError ->
861 Left syntaxError ->
830− return (SOutsideErr (Problem.SyntaxProblem path time syntaxError))
862+ return $ SOutsideErr $
863+ Error.Module "???" path time source (Error.BadSyntax syntaxError)
831
864
832
865
833
866
@@ -837,20 +870,20 @@ crawlMain env@(Env _ _ pkg _ _ _) mvar given =
837data MainResult
870data MainResult
838 = RInside ModuleName.Raw
871 = RInside ModuleName.Raw
839 | ROutsideOk ModuleName.Raw I.Interface Opt.LocalGraph
872 | ROutsideOk ModuleName.Raw I.Interface Opt.LocalGraph
840− | ROutsideErr Problem.Problem
873+ | ROutsideErr Error.Module
841 | ROutsideBlocked
874 | ROutsideBlocked
842
875
843
876
844−checkMain :: Env -> ResultDict -> MainStatus -> IO MainResult
877+checkMain :: Env -> Dependencies -> ResultDict -> MainStatus -> IO MainResult
845−checkMain env@(Env _ root _ _ _ _) results pendingMain =
878+checkMain env@(Env _ root _ _ _ _) foreigns results pendingMain =
846 case pendingMain of
879 case pendingMain of
847 SInside name ->
880 SInside name ->
848 return (RInside name)
881 return (RInside name)
849
882
850− SOutsideErr syntaxProblem ->
883+ SOutsideErr err ->
851− return (ROutsideErr (Problem.BadSyntax syntaxProblem))
884+ return (ROutsideErr err)
852
885
853− SOutsideOk local@(Details.Local _ _ deps _) source modul ->
886+ SOutsideOk local@(Details.Local path time deps _) source modul@(Src.Module _ _ imports _ _ _ _ _) ->
854 do depsStatus <- checkDeps root results deps
887 do depsStatus <- checkDeps root results deps
855 case depsStatus of
888 case depsStatus of
856 DepsChange ifaces ->
889 DepsChange ifaces ->
@@ -869,8 +902,9 @@ checkMain env@(Env _ root _ _ _ _) results pendingMain =
869 DepsBlock ->
902 DepsBlock ->
870 return ROutsideBlocked
903 return ROutsideBlocked
871
904
872− DepsNotFound name1 problem1 others ->
905+ DepsNotFound problems ->
873− return (ROutsideErr (Problem.BadImports name1 problem1 others))
906+ return $ ROutsideErr $ Error.Module (Src.getName modul) path time source $
907+ Error.BadImports (toImportErrors foreigns results imports problems)
874
908
875
909
876compileOutside :: Env -> Details.Local -> B.ByteString -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> MainResult
910compileOutside :: Env -> Details.Local -> B.ByteString -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> MainResult
@@ -883,8 +917,8 @@ compileOutside (Env _ _ pkg _ _ _) (Details.Local path time _ _) source ifaces m
883 ROutsideOk name (I.fromModule pkg canonical annotations) objects
917 ROutsideOk name (I.fromModule pkg canonical annotations) objects
884
918
885 Left errors ->
919 Left errors ->
886− ROutsideErr $ Problem.BadContent $
920+ ROutsideErr $
887− Problem.Module name path time source errors (Localizer.fromModule modul)
921+ Error.Module name path time source errors
888
922
889
923
890
924
@@ -899,34 +933,34 @@ data Main
899toArtifacts :: Env -> Dependencies -> Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either Exit.BuildProblem Artifacts
933toArtifacts :: Env -> Dependencies -> Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either Exit.BuildProblem Artifacts
900toArtifacts (Env _ _ pkg _ _ _) foreigns results mainResults =
934toArtifacts (Env _ _ pkg _ _ _) foreigns results mainResults =
901 case gatherProblemsOrMains results mainResults of
935 case gatherProblemsOrMains results mainResults of
902− Left (NE.List p ps) ->
936+ Left (NE.List e es) ->
903− Left (Exit.BuildModuleProblems p ps)
937+ Left (Exit.BuildModuleProblems e es)
904
938
905 Right mains ->
939 Right mains ->
906 Right $ Artifacts pkg foreigns mains $
940 Right $ Artifacts pkg foreigns mains $
907 Map.foldrWithKey addInside (foldr addOutside [] mainResults) results
941 Map.foldrWithKey addInside (foldr addOutside [] mainResults) results
908
942
909
943
910−gatherProblemsOrMains :: Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either (NE.List Problem.Problem) (NE.List Main)
944+gatherProblemsOrMains :: Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either (NE.List Error.Module) (NE.List Main)
911gatherProblemsOrMains results (NE.List mainResult mainResults) =
945gatherProblemsOrMains results (NE.List mainResult mainResults) =
912 let
946 let
913− sortMain result (ps, mains) =
947+ sortMain result (es, mains) =
914 case result of
948 case result of
915− RInside n -> ( ps, Inside n : mains)
949+ RInside n -> ( es, Inside n : mains)
916− ROutsideOk n i o -> ( ps, Outside n i o : mains)
950+ ROutsideOk n i o -> ( es, Outside n i o : mains)
917− ROutsideErr p -> (p:ps, mains)
951+ ROutsideErr e -> (e:es, mains)
918− ROutsideBlocked -> ( ps, mains)
952+ ROutsideBlocked -> ( es, mains)
919
953
920− problems = Map.foldr addProblem [] results
954+ errors = Map.foldr addErrors [] results
921 in
955 in
922− case (mainResult, foldr sortMain (problems, []) mainResults) of
956+ case (mainResult, foldr sortMain (errors, []) mainResults) of
923 (RInside n , ( [], ms)) -> Right (NE.List (Inside n) ms)
957 (RInside n , ( [], ms)) -> Right (NE.List (Inside n) ms)
924− (RInside _ , (p:ps, _ )) -> Left (NE.List p ps)
958+ (RInside _ , (e:es, _ )) -> Left (NE.List e es)
925 (ROutsideOk n i o, ( [], ms)) -> Right (NE.List (Outside n i o) ms)
959 (ROutsideOk n i o, ( [], ms)) -> Right (NE.List (Outside n i o) ms)
926− (ROutsideOk _ _ _, (p:ps, _ )) -> Left (NE.List p ps)
960+ (ROutsideOk _ _ _, (e:es, _ )) -> Left (NE.List e es)
927− (ROutsideErr p , ( ps, _ )) -> Left (NE.List p ps)
961+ (ROutsideErr e , ( es, _ )) -> Left (NE.List e es)
928 (ROutsideBlocked , ( [], _ )) -> error "seems like elm-stuff/ is corrupted"
962 (ROutsideBlocked , ( [], _ )) -> error "seems like elm-stuff/ is corrupted"
929− (ROutsideBlocked , (p:ps, _ )) -> Left (NE.List p ps)
963+ (ROutsideBlocked , (e:es, _ )) -> Left (NE.List e es)
930
964
931
965
932addInside :: ModuleName.Raw -> Result -> [Module] -> [Module]
966addInside :: ModuleName.Raw -> Result -> [Module] -> [Module]
compiler/src/Reporting/Error/Import.hs+32−28
@@ -1,54 +1,58 @@
1+{-# LANGUAGE OverloadedStrings #-}
1module Reporting.Error.Import
2module Reporting.Error.Import
2 ( Error(..)
3 ( Error(..)
4+ , Problem(..)
3 , toReport
5 , toReport
4 )
6 )
5 where
7 where
6
8
7
9
10+import qualified Data.Set as Set
11+
8import qualified Elm.ModuleName as ModuleName
12import qualified Elm.ModuleName as ModuleName
9import qualified Elm.Package as Pkg
13import qualified Elm.Package as Pkg
14+import qualified Reporting.Doc as D
15+import qualified Reporting.Render.Code as Code
10import qualified Reporting.Report as Report
16import qualified Reporting.Report as Report
17+import qualified Reporting.Annotation as A
11
18
12
19
13
20
14-- ERROR
21-- ERROR
15
22
16
23
17−data Error
24+data Error =
18− = NotFound ModuleName.Raw
25+ Error A.Region ModuleName.Raw (Set.Set ModuleName.Raw) Problem
19− | Ambiguous ModuleName.Raw FilePath [FilePath] Pkg.Name [Pkg.Name]
20− | AmbiguousLocal ModuleName.Raw FilePath FilePath [FilePath]
21− | AmbiguousForeign ModuleName.Raw Pkg.Name Pkg.Name [Pkg.Name]
22−
23−
24−
25−-- TO REPORT
26−
27
26
28−toReport :: Error -> Report.Report
29−toReport err =
30− case err of
31− NotFound name ->
32− error "TODO NotFound" name
33
27
34− Ambiguous name path paths pkg pkgs ->
28+data Problem
35− error "TODO Ambiguous" name path paths pkg pkgs
29+ = NotFound
30+ | Ambiguous FilePath [FilePath] Pkg.Name [Pkg.Name]
31+ | AmbiguousLocal FilePath FilePath [FilePath]
32+ | AmbiguousForeign Pkg.Name Pkg.Name [Pkg.Name]
36
33
37− AmbiguousLocal name path1 path2 paths ->
38− error "TODO AmbiguousLocal" name path1 path2 paths
39
34
40− AmbiguousForeign name pkg1 pkg2 pkgs ->
41− error "TODO AmbiguousForeign" name pkg1 pkg2 pkgs
42
35
36+-- TO REPORT
43
37
44−{-
45−
46−-- MODULE NOT FOUND ---------------------------------------------- src/Main.elm
47
38
39+toReport :: Code.Source -> Error -> Report.Report
40+toReport source (Error region name knownModules problem) =
41+ case problem of
42+ NotFound ->
43+ Report.Report "MODULE NOT FOUND" region [] $
44+ Report.toCodeSnippet source region Nothing
45+ (
48−You are trying to import a `Whatever` module:
46+ "You are trying to import a `" <> D.fromName name <> "` module:"
47+ ,
48+ error "TODO But I cannot find `Whatever` in your project or packages." knownModules
49+ )
49
50
50− import Whatever
51+ Ambiguous path paths pkg pkgs ->
52+ error "TODO Ambiguous" path paths pkg pkgs
51
53
52−But I cannot find `Whatever` in your project or packages.
54+ AmbiguousLocal path1 path2 paths ->
55+ error "TODO AmbiguousLocal" path1 path2 paths
53
56
54−-}
57+ AmbiguousForeign pkg1 pkg2 pkgs ->
58+ error "TODO AmbiguousForeign" pkg1 pkg2 pkgs