Skip to content

Commit

Permalink
detect missing extra-deps missing from indices
Browse files Browse the repository at this point in the history
* it should now detect typos commercialhaskell#1521
  (package suggestions will be added in another PR)
  • Loading branch information
luigy committed Feb 29, 2016
1 parent e7b331f commit 2a95c77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,24 @@ extendExtraDeps :: (MonadThrow m, MonadReader env m, HasBuildConfig env)
-> Map PackageName Version -- ^ latest versions in indices
-> m (Map PackageName Version) -- ^ new extradeps
extendExtraDeps extraDeps0 cliExtraDeps unknowns latestVersion
| null errs = return $ Map.unions $ extraDeps1 : unknowns'
| null errs && null missing = return $ Map.unions $ extraDeps1 : unknowns'
| otherwise = do
bconfig <- asks getBuildConfig

unless (null missing) $
throwM $ UnknownPackageIdentifiers
(Set.fromList $ map fromTuple $ Map.toList missing)
""

throwM $ UnknownTargets
(Set.fromList errs)
Map.empty -- TODO check the cliExtraDeps for presence in index
(bcStackYaml bconfig)
where
extraDeps1 = Map.union extraDeps0 cliExtraDeps
(missing, extraDeps1) =
Map.partitionWithKey missingFromIndex $ Map.union extraDeps0 cliExtraDeps

missingFromIndex name _ = isNothing $ Map.lookup name latestVersion

(errs, unknowns') = partitionEithers $ map addUnknown $ Set.toList unknowns
addUnknown pn =
Expand Down
9 changes: 0 additions & 9 deletions src/Stack/Fetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ data FetchException
| Couldn'tReadPackageTarball FilePath SomeException
| UnpackDirectoryAlreadyExists (Set FilePath)
| CouldNotParsePackageSelectors [String]
| UnknownPackageNames (Set PackageName)
| UnknownPackageIdentifiers (Set PackageIdentifier) String
deriving Typeable
instance Exception FetchException

Expand All @@ -110,13 +108,6 @@ instance Show FetchException where
show (CouldNotParsePackageSelectors strs) =
"The following package selectors are not valid package names or identifiers: " ++
intercalate ", " strs
show (UnknownPackageNames names) =
"The following packages were not found in your indices: " ++
intercalate ", " (map packageNameString $ Set.toList names)
show (UnknownPackageIdentifiers idents suggestions) =
"The following package identifiers were not found in your indices: " ++
intercalate ", " (map packageIdentifierString $ Set.toList idents) ++
(if null suggestions then "" else "\n" ++ suggestions)

-- | Fetch packages into the cache without unpacking
fetchPackages :: (MonadIO m, MonadBaseControl IO m, MonadReader env m, HasHttpManager env, HasConfig env, MonadThrow m, MonadLogger m, MonadCatch m)
Expand Down
9 changes: 9 additions & 0 deletions src/Stack/Types/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ data PackageException
| PackageNoCabalFileFound (Path Abs Dir)
| PackageMultipleCabalFilesFound (Path Abs Dir) [Path Abs File]
| MismatchedCabalName (Path Abs File) PackageName
| UnknownPackageNames (Set PackageName)
| UnknownPackageIdentifiers (Set PackageIdentifier) String
deriving Typeable
instance Exception PackageException
instance Show PackageException where
Expand Down Expand Up @@ -77,6 +79,13 @@ instance Show PackageException where
, ".cabal\n"
, "For more information, see: https://github.com/commercialhaskell/stack/issues/317"
]
show (UnknownPackageNames names) =
"The following packages were not found in your indices: " ++
intercalate ", " (map packageNameString $ Set.toList names)
show (UnknownPackageIdentifiers idents suggestions) =
"The following package identifiers were not found in your indices: " ++
intercalate ", " (map packageIdentifierString $ Set.toList idents) ++
(if null suggestions then "" else "\n" ++ suggestions)

-- | Some package info.
data Package =
Expand Down

0 comments on commit 2a95c77

Please sign in to comment.