Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #117 Add error S-628 LocalNoArchiveFileFound #118

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- master
workflow_dispatch:

# As of 27 September 2023, ubuntu-latest and windows-latest come with
# Stack 2.11.1 and macos-latest comes with Stack 2.9.3.
# As of 2 December 2023, ubuntu-latest, windows-latest and macos-latest come
# with Stack 2.13.1.

jobs:
build:
Expand All @@ -21,7 +21,7 @@ jobs:
- ubuntu-latest
resolver:
- stack-ghc-9.2.8.yaml
- stack-ghc-9.4.7.yaml
- stack-ghc-9.4.8.yaml
- stack-ghc-9.6.3.yaml
include:
- os: macos-latest
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- ubuntu-latest
- windows-latest
resolver:
- stack-ghc-9.4.7.yaml
- stack-ghc-9.4.8.yaml
steps:
- name: Clone project
uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog for pantry

## v0.9.2.1
## v0.9.3

* Add error S-628 (`LocalNoArchiveFileFound`).
* Depend on `rio-prettyprint-0.1.7.0`.

## v0.9.2
Expand Down
1 change: 1 addition & 0 deletions app/test-pretty-exceptions/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ examples = concat
, [ DownloadInvalidSHA256 urlExample (Mismatch sha256Example sha256Example) ]
, [ DownloadInvalidSize urlExample (Mismatch fileSizeExample fileSizeExample) ]
, [ DownloadTooLarge urlExample (Mismatch fileSizeExample fileSizeExample) ]
, [ LocalNoArchiveFileFound pathAbsFileExample ]
, [ LocalInvalidSHA256 pathAbsFileExample (Mismatch sha256Example sha256Example) ]
, [ LocalInvalidSize pathAbsFileExample (Mismatch fileSizeExample fileSizeExample) ]
, [ UnknownArchiveType archiveLocation
Expand Down
40 changes: 32 additions & 8 deletions int/Pantry/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ data PantryException
| DownloadTooLarge !Text !(Mismatch FileSize)
-- ^ Different from 'DownloadInvalidSize' since 'mismatchActual' is
-- a lower bound on the size from the server.
| LocalNoArchiveFileFound !(Path Abs File)
| LocalInvalidSHA256 !(Path Abs File) !(Mismatch SHA256)
| LocalInvalidSize !(Path Abs File) !(Mismatch FileSize)
| UnknownArchiveType !ArchiveLocation
Expand Down Expand Up @@ -1186,17 +1187,19 @@ instance Display PantryException where
<> "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"
<> "Stack looks for packages in the directories configured in the\n"
<> "'packages' and 'extra-deps' fields defined in its project-level\n"
<> "configuration file (usually 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"
<> "the 'packages' and 'extra-deps' fields defined in your stack.yaml\n"
<> "Stack looks for packages in the directories configured in the\n"
<> "'packages' and 'extra-deps' fields defined in its project-level\n"
<> "configuration file (usually stack.yaml)\n"
<> "The current entry points to "
<> fromString (toFilePath dir)
<> ",\nbut no .cabal or package.yaml file could be found there."
Expand Down Expand Up @@ -1300,6 +1303,14 @@ instance Display PantryException where
<> display mismatchExpected
<> ", stopped after receiving: "
<> display mismatchActual
display (LocalNoArchiveFileFound path) =
"Error: [S-628]\n"
<> "Stack looks for packages in the archive files configured in the\n"
<> "'extra-deps' field defined in its project-level configuration file\n"
<> "(usually stack.yaml)\n"
<> "An entry points to "
<> fromString (toFilePath path)
<> ",\nbut no such archive file could be found."
display (LocalInvalidSHA256 path Mismatch {..}) =
"Error: [S-834]\n"
<> "Mismatched SHA256 hash from "
Expand Down Expand Up @@ -1541,8 +1552,8 @@ instance Pretty PantryException where
, style Shell "packages"
, "and"
, style Shell "extra-deps"
, flow "fields defined in your"
, style File "stack.yaml" <> "."
, flow "fields defined in its project-level configuration file"
, parens (fillSep ["usually", style File "stack.yaml"]) <> "."
, flow "The current entry points to"
, pretty dir
, flow "but no such directory could be found. If, alternatively, a"
Expand All @@ -1557,8 +1568,8 @@ instance Pretty PantryException where
, style Shell "packages"
, "and"
, style Shell "extra-deps"
, flow "fields defined in your"
, style File "stack.yaml" <> "."
, flow "fields defined in its project-level configuration file"
, parens (fillSep ["usually", style File "stack.yaml"]) <> "."
, flow "The current entry points to"
, pretty dir
, flow "but no Cabal file or"
Expand Down Expand Up @@ -1729,6 +1740,19 @@ instance Pretty PantryException where
, flow "stopped after receiving:"
, fromString . T.unpack $ textDisplay mismatchActual <> "."
]
pretty (LocalNoArchiveFileFound path) =
"[S-628]"
<> line
<> fillSep
[ flow "Stack looks for packages in the archive files configured in"
, "the"
, style Shell "extra-deps"
, flow "field defined in its project-level configuration file"
, parens (fillSep ["usually", style File "stack.yaml"]) <> "."
, flow "An entry points to"
, pretty path
, flow "but no such archive file could be found."
]
pretty (LocalInvalidSHA256 path Mismatch {..}) =
"[S-834]"
<> line
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.9.2
version: 0.9.3
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: 6 additions & 1 deletion src/Pantry/Archive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Pantry.Types
, toRawArchive, toRawPM, unSafeFilePath
)
import Path ( toFilePath )
import Path.IO ( doesFileExist )
import RIO
import qualified RIO.ByteString.Lazy as BL
import qualified RIO.List as List
Expand Down Expand Up @@ -236,7 +237,8 @@ checkPackageMetadata pl pm pa = do
in if and tests then Right pa else Left err

-- | Provide a local file with the contents of the archive, regardless of where
-- it comes from. Perform SHA256 and file size validation if downloading.
-- it comes from. If not downloading, checks that the archive file exists.
-- Performs SHA256 and file size validation.
withArchiveLoc ::
HasLogFunc env
=> RawArchive
Expand All @@ -245,6 +247,9 @@ withArchiveLoc ::
withArchiveLoc (RawArchive (ALFilePath resolved) msha msize _subdir) f = do
let abs' = resolvedAbsolute resolved
fp = toFilePath abs'
archiveExists <- doesFileExist abs'
unless archiveExists $
throwIO $ LocalNoArchiveFileFound abs'
(sha, size) <- withBinaryFile fp ReadMode $ \h -> do
size <- FileSize . fromIntegral <$> hFileSize h
for_ msize $ \size' ->
Expand Down
14 changes: 7 additions & 7 deletions stack-ghc-9.4.7.yaml → stack-ghc-9.4.8.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Snapshot specification for GHC 9.4.7.
resolver: lts-21.19 # GHC 9.4.7
# Snapshot specification for GHC 9.4.8.
resolver: lts-21.22 # GHC 9.4.8

packages:
- aeson-warning-parser-0.1.0@sha256:f2c1c42b73aa35d352060abcbb867c410cbbf57d0cb0fed607bcd1e2a74954ad,1308
Expand All @@ -9,16 +9,16 @@ packages:
- crypton-x509-store-1.6.9@sha256:422b9b9f87a7382c66385d047615b16fc86a68c08ea22b1e0117c143a2d44050,1750
- crypton-x509-system-1.6.7@sha256:023ed573d82983bc473a37a89e0434a085b413be9f68d07e085361056afd4637,1532
- crypton-x509-validation-1.6.12@sha256:85989721b64be4b90de9f66ef641c26f57575cffed1a50d707065fb60176f386,2227
# lts-21.19 provides hpack-0.35.2
# lts-21.22 provides hpack-0.35.2
- hpack-0.36.0@sha256:c2daa6556afc57367a5d1dbd878bf515d442d201e24b27473051359abd47ed08,5187
# lts-21.19 provides http-client-tls-0.3.6.1
# lts-21.22 provides http-client-tls-0.3.6.1
- http-client-tls-0.3.6.3@sha256:a5909ce412ee65c141b8547f8fe22236f175186c95c708e86a46b5547394f910,2046
# lts-21.19 provides http-download-0.2.0.0
# lts-21.22 provides http-download-0.2.0.0
- http-download-0.2.1.0@sha256:a97863e96f7d44efc3d0e3061db7fe2540b8374ca44ae90d0b56040140cb7506,1716
- static-bytes-0.1.0@sha256:35dbf30f617baa0151682c97687042516be07872a39984f9fe31f78125b962bf,1627
# lts-21.19 provides tar-conduit-0.3.2.1
# lts-21.22 provides tar-conduit-0.3.2.1
- tar-conduit-0.4.0@sha256:f333649770f5ec42a83a93b0d424cf6bb895d80dfbee05a54340395f81d036ae,3126
# crypton-connection-0.3.1 requires tls >= 1.7. lts-21.19 provides tls-1.6.0
# crypton-connection-0.3.1 requires tls >= 1.7. lts-21.22 provides tls-1.6.0
- tls-1.8.0@sha256:0ea435fb1969384c76e6b6ba49c509cec55eec29f60dd2c335151d9c8a4e8b4f,5571

flags:
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
resolver: stack-ghc-9.4.7.yaml
resolver: stack-ghc-9.4.8.yaml
8 changes: 4 additions & 4 deletions stack.yaml.lock

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