Skip to content

Commit

Permalink
Merge pull request #86 from commercialhaskell/fix-stack6114
Browse files Browse the repository at this point in the history
Re Stack #6114 add error S-395 (`NoLocalPackageDirFound`)
  • Loading branch information
mpilgrem authored May 4, 2023
2 parents 29385cd + 8e21ec0 commit caddf4a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/commercialhaskell/pantry#readme>
category: Development
Expand Down
2 changes: 1 addition & 1 deletion pantry.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/Pantry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/Pantry/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit caddf4a

Please sign in to comment.