From 8e21ec0a5fbb0631037dac15152a1b4e70b38380 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Thu, 4 May 2023 17:33:12 +0100 Subject: [PATCH] Re Stack #6114 add error S-395 (`NoLocalPackageDirFound`) --- ChangeLog.md | 4 ++++ package.yaml | 2 +- pantry.cabal | 2 +- src/Pantry.hs | 7 +++++-- src/Pantry/Types.hs | 26 ++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index a8ac9081..9460c190 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Changelog for pantry +## v0.8.2.2 + +* Add error S-395 (`NoLocalPackageDirFound`). + ## v0.8.2.1 * On Windows, avoid fatal `tar: Cannot connect to C: resolve failed` bug when diff --git a/package.yaml b/package.yaml index fa120ad8..c698e721 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: pantry -version: 0.8.2.1 +version: 0.8.2.2 synopsis: Content addressable Haskell package management description: Please see the README on GitHub at category: Development diff --git a/pantry.cabal b/pantry.cabal index 24a2f183..04b5e84f 100644 --- a/pantry.cabal +++ b/pantry.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: pantry -version: 0.8.2.1 +version: 0.8.2.2 synopsis: Content addressable Haskell package management description: Please see the README on GitHub at category: Development diff --git a/src/Pantry.hs b/src/Pantry.hs index 54dcf68b..201d0162 100644 --- a/src/Pantry.hs +++ b/src/Pantry.hs @@ -239,6 +239,7 @@ import Data.Time (getCurrentTime, diffUTCTime) import Data.Yaml.Include (decodeFileWithWarnings) import Hpack.Yaml (formatWarning) import Hpack.Error (formatHpackError) +import System.IO.Error (isDoesNotExistError) decodeYaml :: FilePath -> IO (Either String ([String], Value)) decodeYaml file = do @@ -732,8 +733,10 @@ findOrGenerateCabalFile findOrGenerateCabalFile progName pkgDir = do let hpackProgName = fromString . unpack <$> progName hpack hpackProgName pkgDir - files <- filter (flip hasExtension "cabal" . toFilePath) . snd - <$> listDir pkgDir + (_, allFiles) <- listDir pkgDir `catchIO` \e -> if isDoesNotExistError e + then throwIO $ NoLocalPackageDirFound pkgDir + else throwIO e + let files = filter (flip hasExtension "cabal" . toFilePath) allFiles -- If there are multiple files, ignore files that start with -- ".". On unixlike environments these are hidden, and this -- character is not valid in package names. The main goal is diff --git a/src/Pantry/Types.hs b/src/Pantry/Types.hs index 7f3d3749..1ce9cd8c 100644 --- a/src/Pantry/Types.hs +++ b/src/Pantry/Types.hs @@ -966,6 +966,7 @@ data PantryException | TreeWithoutCabalFile !RawPackageLocationImmutable | TreeWithMultipleCabalFiles !RawPackageLocationImmutable ![SafeFilePath] | MismatchedCabalName !(Path Abs File) !PackageName + | NoLocalPackageDirFound !(Path Abs Dir) | NoCabalFileFound !(Path Abs Dir) | MultipleCabalFilesFound !(Path Abs Dir) ![Path Abs File] | InvalidWantedCompiler !Text @@ -1086,6 +1087,15 @@ instance Display PantryException where <> ".cabal\n" <> "Hackage rejects packages where the first part of the Cabal file name " <> "is not the package name." + display (NoLocalPackageDirFound dir) = + "Error: [S-395]\n" + <> "Stack looks for packages in the directories configured in\n" + <> "the 'packages' and 'extra-deps' fields defined in your stack.yaml\n" + <> "The current entry points to " + <> fromString (toFilePath dir) + <> ",\nbut no such directory could be found. If, alternatively, a package\n" + <> "in the package index was intended, its name and version must be\n" + <> "specified as an extra-dep." display (NoCabalFileFound dir) = "Error: [S-636]\n" <> "Stack looks for packages in the directories configured in\n" @@ -1422,6 +1432,22 @@ instance Pretty PantryException where , flow "Hackage rejects packages where the first part of the Cabal" , flow "file name is not the package name." ] + pretty (NoLocalPackageDirFound dir) = + "[S-395]" + <> line + <> fillSep + [ flow "Stack looks for packages in the directories configured in the" + , style Shell "packages" + , "and" + , style Shell "extra-deps" + , flow "fields defined in your" + , style File "stack.yaml" <> "." + , flow "The current entry points to" + , pretty dir + , flow "but no such directory could be found. If, alternatively, a" + , flow "package in the package index was intended, its name and" + , flow "version must be specified as an extra-dep." + ] pretty (NoCabalFileFound dir) = "[S-636]" <> line