on master help sign in
add error message when dependencies do not build
commit22e7413e2eca95e3010b39a02d727ccef9ecbb27 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 27 Jun 2019, 15:20 (7 years ago) parentbe0621b
2 files changed+67−24
builder/src/Elm/Details.hs+20−21 builder/src/Reporting/Exit.hs+47−3
builder/src/Elm/Details.hs+20−21
@@ -17,9 +17,11 @@ import Control.Concurrent (forkIO)
1717import Control.Concurrent.MVar (MVar, newEmptyMVar, newMVar, putMVar, readMVar, takeMVar)
1818import Control.Monad (liftM, liftM2, liftM4)
1919import Data.Binary (Binary, get, put, getWord8, putWord8)
20+import qualified Data.Either as Either
2021import qualified Data.Map as Map
2122import qualified Data.Map.Utils as Map
2223import qualified Data.Map.Merge.Strict as Map
24+import qualified Data.Maybe as Maybe
2325import qualified Data.Name as Name
2426import qualified Data.NonEmptyList as NE
2527import qualified Data.OneOrMore as OneOrMore
@@ -294,8 +296,10 @@ verifyDependencies env@(Env key root _ _ _ _) time outline solution directDeps =
294296 putMVar mvar mvars
295297 deps <- traverse readMVar mvars
296298 case sequence deps of
297− Left problem ->
298− error "TODO verifyDependencies" problem
299+ Left _ ->
300+ do home <- Stuff.getElmHome
301+ return $ Left $ Exit.DetailsBadDeps home $
302+ Maybe.catMaybes $ Either.lefts $ Map.elems deps
299303
300304 Right artifacts ->
301305 let
@@ -346,13 +350,7 @@ data Artifacts =
346350
347351
348352type Dep =
349− Either Problem Artifacts
350−
351−
352−data Problem
353− = BadDownload Exit.PackageProblem
354− | BadBuild
355− | BadDependency
353+ Either (Maybe Exit.DetailsBadDep) Artifacts
356354
357355
358356verifyDep :: Env -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Map.Map Pkg.Name Solver.Details -> Pkg.Name -> Solver.Details -> IO Dep
@@ -367,23 +365,23 @@ verifyDep (Env key _ cache manager _ _) depsMVar solution pkg details@(Solver.De
367365 maybeCache <- File.readBinary (Stuff.package cache pkg vsn </> "artifacts.dat")
368366 case maybeCache of
369367 Nothing ->
370− build key cache depsMVar pkg details (Set.singleton fingerprint)
368+ build key cache depsMVar pkg details fingerprint Set.empty
371369
372370 Just (ArtifactCache fingerprints artifacts) ->
373371 if Set.member fingerprint fingerprints
374372 then Reporting.report key Reporting.DBuilt >> return (Right artifacts)
375− else build key cache depsMVar pkg details (Set.insert fingerprint fingerprints)
373+ else build key cache depsMVar pkg details fingerprint fingerprints
376374 else
377375 do Reporting.report key Reporting.DRequested
378376 result <- downloadPackage cache manager pkg vsn
379377 case result of
380− Left p ->
378+ Left problem ->
381379 do Reporting.report key (Reporting.DFailed pkg vsn)
382− return (Left (BadDownload p))
380+ return $ Left $ Just $ Exit.BD_BadDownload pkg vsn problem
383381
384382 Right () ->
385383 do Reporting.report key (Reporting.DReceived pkg vsn)
386− build key cache depsMVar pkg details (Set.singleton fingerprint)
384+ build key cache depsMVar pkg details fingerprint Set.empty
387385
388386
389387
@@ -405,17 +403,17 @@ type Fingerprint =
405403-- BUILD
406404
407405
408−build :: Reporting.DKey -> Stuff.PackageCache -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Pkg.Name -> Solver.Details -> Set.Set Fingerprint -> IO Dep
409−build key cache depsMVar pkg (Solver.Details vsn _) fingerprints =
406+build :: Reporting.DKey -> Stuff.PackageCache -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Pkg.Name -> Solver.Details -> Fingerprint -> Set.Set Fingerprint -> IO Dep
407+build key cache depsMVar pkg (Solver.Details vsn _) f fs =
410408 do eitherOutline <- Outline.read (Stuff.package cache pkg vsn)
411409 case eitherOutline of
412410 Left _ ->
413411 do Reporting.report key Reporting.DBroken
414− return (Left BadBuild)
412+ return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
415413
416414 Right (Outline.App _) ->
417415 do Reporting.report key Reporting.DBroken
418− return (Left BadBuild)
416+ return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
419417
420418 Right (Outline.Pkg (Outline.PkgOutline _ _ _ _ exposed deps _ _)) ->
421419 do allDeps <- readMVar depsMVar
@@ -423,7 +421,7 @@ build key cache depsMVar pkg (Solver.Details vsn _) fingerprints =
423421 case sequence directDeps of
424422 Left _ ->
425423 do Reporting.report key Reporting.DBroken
426− return (Left BadDependency)
424+ return $ Left $ Nothing
427425
428426 Right directArtifacts ->
429427 do let src = Stuff.package cache pkg vsn </> "src"
@@ -438,7 +436,7 @@ build key cache depsMVar pkg (Solver.Details vsn _) fingerprints =
438436 case sequence maybeStatuses of
439437 Nothing ->
440438 do Reporting.report key Reporting.DBroken
441− return (Left BadBuild)
439+ return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
442440
443441 Just statuses ->
444442 do rmvar <- newEmptyMVar
@@ -448,7 +446,7 @@ build key cache depsMVar pkg (Solver.Details vsn _) fingerprints =
448446 case sequence maybeResults of
449447 Nothing ->
450448 do Reporting.report key Reporting.DBroken
451− return (Left BadBuild)
449+ return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
452450
453451 Just results ->
454452 let
@@ -456,6 +454,7 @@ build key cache depsMVar pkg (Solver.Details vsn _) fingerprints =
456454 ifaces = gatherInterfaces exposedDict results
457455 objects = gatherObjects results
458456 artifacts = Artifacts ifaces objects
457+ fingerprints = Set.insert f fs
459458 in
460459 do writeDocs cache pkg vsn docsStatus results
461460 File.writeBinary path (ArtifactCache fingerprints artifacts)
builder/src/Reporting/Exit.hs+47−3
@@ -14,6 +14,7 @@ module Reporting.Exit
1414 , Outline(..)
1515 , OutlineProblem(..)
1616 , Details(..)
17+ , DetailsBadDep(..)
1718 , PackageProblem(..)
1819 , RegistryProblem(..)
1920 , BuildProblem(..)
@@ -34,6 +35,7 @@ import qualified Data.ByteString.Char8 as BSC
3435import qualified Data.ByteString.Lazy as LBS
3536import qualified Data.ByteString.UTF8 as BS_UTF8
3637import qualified Data.List as List
38+import qualified Data.Map as Map
3739import qualified Data.Name as N
3840import qualified Data.NonEmptyList as NE
3941import qualified Network.HTTP.Client as HTTP
@@ -1194,7 +1196,12 @@ data Details
11941196 | DetailsHandEditedDependencies
11951197 | DetailsBadOutline Outline
11961198 | DetailsCannotGetRegistry RegistryProblem
1197− | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
1199+ | DetailsBadDeps FilePath [DetailsBadDep]
1200+
1201+
1202+data DetailsBadDep
1203+ = BD_BadDownload Pkg.Name V.Version PackageProblem
1204+ | BD_BadBuild Pkg.Name V.Version (Map.Map Pkg.Name V.Version)
11981205
11991206
12001207toDetailsReport :: Details -> Help.Report
@@ -1275,8 +1282,45 @@ toDetailsReport details =
12751282 toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
12761283 "I need the list of published packages to verify your dependencies"
12771284
1278− DetailsCannotBuildPackage pkg vsn problem ->
1279− toPackageProblemReport pkg vsn problem
1285+ DetailsBadDeps cacheDir deps ->
1286+ case deps of
1287+ [] ->
1288+ Help.report "PROBLEM BUILDING DEPENDENCIES" Nothing
1289+ "I am not sure what is going wrong though."
1290+ [ D.reflow $
1291+ "I would try deleting the " ++ cacheDir ++ " and elm-stuff/ directories, then\
1292+ \ trying to build again. That will work if some cached files got corrupted\
1293+ \ somehow."
1294+ , D.reflow $
1295+ "If that does not work, go to https://elm-lang.org/community and ask for\
1296+ \ help. This is a weird case!"
1297+ ]
1298+
1299+ d:_ ->
1300+ case d of
1301+ BD_BadDownload pkg vsn packageProblem ->
1302+ toPackageProblemReport pkg vsn packageProblem
1303+
1304+ BD_BadBuild pkg vsn fingerprint ->
1305+ Help.report "PROBLEM BUILDING DEPENDENCIES" Nothing
1306+ "I ran into a compilation error when trying to build the following package:"
1307+ [ D.indent 4 $ D.red $ D.fromChars $ Pkg.toChars pkg ++ " " ++ V.toChars vsn
1308+ , D.reflow $
1309+ "This probably means it has package constraints that are too wide. It may be\
1310+ \ possible to tweak your elm.json to avoid the root problem as a stopgap. Head\
1311+ \ over to https://elm-lang.org/community to get help figuring out how to take\
1312+ \ this path!"
1313+ , D.toSimpleNote $
1314+ "To help with the root problem, please report this to the package author along\
1315+ \ with the following information:"
1316+ , D.indent 4 $ D.vcat $
1317+ map (\(p,v) -> D.fromChars $ Pkg.toChars p ++ " " ++ V.toChars v) $
1318+ Map.toList fingerprint
1319+ , D.reflow $
1320+ "If you want to help out even more, try building the package locally. That should\
1321+ \ give you much more specific information about why this package is failing to\
1322+ \ build, which will in turn make it easier for the package author to fix it!"
1323+ ]
12801324
12811325
12821326