From 7d4cc9bea79b20a398a8adf1e7897c195a24b301 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sat, 2 Dec 2023 17:54:30 +0000 Subject: [PATCH] Fix #117 Add error S-628 `LocalNoArchiveFileFound` Also improve existing error messages referring to stack.yaml files. Also bump CI. --- .github/workflows/tests.yml | 8 ++-- ChangeLog.md | 3 +- app/test-pretty-exceptions/Main.hs | 1 + int/Pantry/Types.hs | 40 ++++++++++++++++---- package.yaml | 2 +- pantry.cabal | 2 +- src/Pantry/Archive.hs | 7 +++- stack-ghc-9.4.7.yaml => stack-ghc-9.4.8.yaml | 14 +++---- stack.yaml | 2 +- stack.yaml.lock | 8 ++-- 10 files changed, 59 insertions(+), 28 deletions(-) rename stack-ghc-9.4.7.yaml => stack-ghc-9.4.8.yaml (82%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d08a0f74..305ce941 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: @@ -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 @@ -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 diff --git a/ChangeLog.md b/ChangeLog.md index 91a61d10..1fd30f25 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/app/test-pretty-exceptions/Main.hs b/app/test-pretty-exceptions/Main.hs index a89cb038..2d8be7a1 100644 --- a/app/test-pretty-exceptions/Main.hs +++ b/app/test-pretty-exceptions/Main.hs @@ -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 diff --git a/int/Pantry/Types.hs b/int/Pantry/Types.hs index ac764d2c..6dd80243 100644 --- a/int/Pantry/Types.hs +++ b/int/Pantry/Types.hs @@ -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 @@ -1186,8 +1187,9 @@ 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" @@ -1195,8 +1197,9 @@ instance Display PantryException where <> "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." @@ -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 " @@ -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" @@ -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" @@ -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 diff --git a/package.yaml b/package.yaml index cdeffa3d..125cf204 100644 --- a/package.yaml +++ b/package.yaml @@ -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 category: Development diff --git a/pantry.cabal b/pantry.cabal index 51310d88..e2a0349a 100644 --- a/pantry.cabal +++ b/pantry.cabal @@ -5,7 +5,7 @@ cabal-version: 2.0 -- see: https://github.com/sol/hpack name: pantry -version: 0.9.2 +version: 0.9.3 synopsis: Content addressable Haskell package management description: Please see the README on GitHub at category: Development diff --git a/src/Pantry/Archive.hs b/src/Pantry/Archive.hs index d246a8ec..5c89ad15 100644 --- a/src/Pantry/Archive.hs +++ b/src/Pantry/Archive.hs @@ -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 @@ -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 @@ -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' -> diff --git a/stack-ghc-9.4.7.yaml b/stack-ghc-9.4.8.yaml similarity index 82% rename from stack-ghc-9.4.7.yaml rename to stack-ghc-9.4.8.yaml index 25b08190..92363272 100644 --- a/stack-ghc-9.4.7.yaml +++ b/stack-ghc-9.4.8.yaml @@ -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 @@ -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: diff --git a/stack.yaml b/stack.yaml index 8331c235..b41dcba3 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1 +1 @@ -resolver: stack-ghc-9.4.7.yaml +resolver: stack-ghc-9.4.8.yaml diff --git a/stack.yaml.lock b/stack.yaml.lock index 339ced54..00ab4f0a 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -97,7 +97,7 @@ packages: hackage: tls-1.8.0@sha256:0ea435fb1969384c76e6b6ba49c509cec55eec29f60dd2c335151d9c8a4e8b4f,5571 snapshots: - completed: - sha256: fb482b8e2d5d061cdda4ba1da2957c012740c893a5ee1c1b99001adae7b1fbe7 - size: 640046 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/19.yaml - original: lts-21.19 + sha256: afd5ba64ab602cabc2d3942d3d7e7dd6311bc626dcb415b901eaf576cb62f0ea + size: 640060 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/22.yaml + original: lts-21.22