From 56f0bc54be601c41a03853ccb7986d42f8de7ce0 Mon Sep 17 00:00:00 2001 From: Robin Heggelund Hansen Date: Mon, 13 Mar 2023 20:23:24 +0100 Subject: [PATCH] Improve error message when there's something wrong with a local dependency. --- builder/src/Deps/Solver.hs | 16 ++++----- builder/src/Reporting/Exit.hs | 64 ++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/builder/src/Deps/Solver.hs b/builder/src/Deps/Solver.hs index 8410e8c5..52b98815 100644 --- a/builder/src/Deps/Solver.hs +++ b/builder/src/Deps/Solver.hs @@ -171,7 +171,7 @@ data ConstraintSource -- TODO: Avoid re-reading the gren.json for local dependencies resolveToConstraintSource :: Pkg.Name -> PossibleFilePath C.Constraint -> Solver ConstraintSource -resolveToConstraintSource pkgName possibleFP = +resolveToConstraintSource expectedPkgName possibleFP = Solver $ \state ok back err -> case possibleFP of PossibleFilePath.Other cons -> @@ -184,15 +184,15 @@ resolveToConstraintSource pkgName possibleFP = let outlinePath = fp "gren.json" bytes <- File.readUtf8 outlinePath case D.fromByteString Outline.decoder bytes of - Right (Outline.Pkg (Outline.PkgOutline outlineName _ _ version _ _ _ _)) -> - if outlineName /= pkgName - then err $ Exit.SolverBadLocalDep pkgName fp + Right (Outline.Pkg (Outline.PkgOutline pkgName _ _ version _ _ _ _)) -> + if expectedPkgName /= pkgName + then err $ Exit.SolverBadLocalDepWrongName fp expectedPkgName pkgName else ok state (Local (C.exactly version) fp) back - Right _ -> - err $ Exit.SolverBadLocalDep pkgName fp + Right (Outline.App _) -> + err $ Exit.SolverBadLocalDepExpectedPkg fp expectedPkgName Left _ -> - err $ Exit.SolverBadLocalDep pkgName fp - else err $ Exit.SolverBadLocalDep pkgName fp + err $ Exit.SolverBadLocalDepInvalidGrenJson fp expectedPkgName + else err $ Exit.SolverLocalDepNotFound fp expectedPkgName constraintFromCS :: ConstraintSource -> C.Constraint constraintFromCS source = diff --git a/builder/src/Reporting/Exit.hs b/builder/src/Reporting/Exit.hs index 24acdc3f..a84d8670 100644 --- a/builder/src/Reporting/Exit.hs +++ b/builder/src/Reporting/Exit.hs @@ -992,14 +992,19 @@ outdatedToReport exit = OutdatedBadOutline outline -> toOutlineReport outline OutdatedGitTrouble gitError -> - toGitErrorReport "PROBLEM FINDING OUTDATED PACKAGE VERSIONS" gitError $ + toGitErrorReport + "PROBLEM FINDING OUTDATED PACKAGE VERSIONS" + gitError "I tried to find newer versions of the dependencies specified in your gren.json file." -- SOLVER data Solver = SolverBadCacheData Pkg.Name V.Version - | SolverBadLocalDep Pkg.Name String + | SolverBadLocalDepWrongName FilePath Pkg.Name Pkg.Name + | SolverBadLocalDepExpectedPkg FilePath Pkg.Name + | SolverBadLocalDepInvalidGrenJson FilePath Pkg.Name + | SolverLocalDepNotFound FilePath Pkg.Name | SolverBadGitOperationUnversionedPkg Pkg.Name Git.Error | SolverBadGitOperationVersionedPkg Pkg.Name V.Version Git.Error | SolverIncompatibleSolvedVersion Pkg.Name Pkg.Name C.Constraint V.Version @@ -1026,19 +1031,60 @@ toSolverReport problem = \ Hopefully that will get you unstuck, but it will not resolve the root\ \ problem if a 3rd party tool is modifing cached files for some reason." ] - SolverBadLocalDep pkg filePath -> + SolverBadLocalDepWrongName filePath expectedPkgName actualPkgName -> Help.report "PROBLEM SOLVING PACKAGE CONSTRAINTS" Nothing - ( "I need the gren.json of " - ++ Pkg.toChars pkg - ++ " (located at " + ( "You have included " + ++ Pkg.toChars expectedPkgName + ++ " as a local dependency (located at " + ++ filePath + ++ ") but the gren.json file says that the package name is " + ++ Pkg.toChars actualPkgName + ++ "." + ) + [ D.reflow + "Verify that the path is correct, and that the name is set correctly." + ] + SolverBadLocalDepExpectedPkg filePath expectedPkgName -> + Help.report + "PROBLEM SOLVING PACKAGE CONSTRAINTS" + Nothing + ( "You have included " + ++ Pkg.toChars expectedPkgName + ++ " as a local dependency (located at " + ++ filePath + ++ ") but the gren.json file says that it is an application, and not a package." + ) + [ D.reflow + "Verify that the path is correct, and that the project is setup correctly." + ] + SolverBadLocalDepInvalidGrenJson filePath expectedPkgName -> + Help.report + "PROBLEM SOLVING PACKAGE CONSTRAINTS" + Nothing + ( "You have included " + ++ Pkg.toChars expectedPkgName + ++ " as a local dependency (located at " + ++ filePath + ++ ") but I'm having trouble parsing its gren.json file." + ) + [ D.reflow + "Verify that the path is correct, and that the project is setup correctly. \ + \It might help to run gren make at this location." + ] + SolverLocalDepNotFound filePath expectedPkgName -> + Help.report + "PROBLEM SOLVING PACKAGE CONSTRAINTS" + Nothing + ( "You have included " + ++ Pkg.toChars expectedPkgName + ++ " as a local dependency (located at " ++ filePath - ++ ") to help me search for a set of compatible packages. It seems to be a dependency\ - \ that resides on your disk." + ++ ") but I cannot find a gren.json file at that location." ) [ D.reflow - "Verify that the path is correct, that it is defined as a package and that it compiles." + "Verify that the path is correct." ] SolverBadGitOperationUnversionedPkg pkg gitError -> toGitErrorReport "PROBLEM SOLVING PACKAGE CONSTRAINTS" gitError $