Skip to content

Commit

Permalink
Merge pull request #199 from gren-lang/detect-bad-package-name-for-lo…
Browse files Browse the repository at this point in the history
…cal-dep

Detect bad package name for local dep
  • Loading branch information
robinheghan authored Mar 13, 2023
2 parents 63d9a6f + 56f0bc5 commit b8c2fec
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
16 changes: 9 additions & 7 deletions builder/src/Deps/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -184,13 +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 _ _ _ version _ _ _ _)) ->
ok state (Local (C.exactly version) fp) back
Right _ ->
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 (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 =
Expand Down
64 changes: 55 additions & 9 deletions builder/src/Reporting/Exit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $
Expand Down

0 comments on commit b8c2fec

Please sign in to comment.