From dd37355ee570f38c9489e4277533f3a0f2c8ed36 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Wed, 7 Dec 2022 14:07:23 +0000 Subject: [PATCH] Fix Hpack #530 Make use of prettier Hpack error messages Prettier Hpack error messages are enabled by hpack-0.35.1. For the context to this pull request see [Hpack issue #530](https://github.com/sol/hpack/issues/530), the [Hpack PR #531](https://github.com/sol/hpack/pull/531) and the alternative [Hpack PR #535](https://github.com/sol/hpack/pull/535) (on which this PR builds). Also conforms form of messages of Errors [S-305] and [S-720] and the naming of arguments (`err`) in the `PantryException` instance of `Display`. Also bumps from lts-20.0 to lts-20.4 (most recent GHC 9.2.5). --- package.yaml | 4 ++-- pantry.cabal | 6 +++--- src/Pantry.hs | 37 +++++++++++++++++++++++++++------ src/Pantry/Types.hs | 30 +++++++++++++------------- stack-cabal-3.4.yaml | 1 + stack-cabal-3.4.yaml.lock | 7 +++++++ stack-ghc-8.6.5.yaml | 2 +- stack-ghc-8.6.5.yaml.lock | 8 +++---- stack-ghc-8.8.4.yaml | 2 +- stack-ghc-8.8.4.yaml.lock | 8 +++---- stack-ghc-9.2.5.yaml | 5 ++++- stack-ghc-9.2.5.yaml.lock | 17 ++++++++++----- stack-ghc-9.4.3.yaml | 3 ++- stack-ghc-9.4.3.yaml.lock | 9 +++++++- stack-persistent-2.11.yaml | 1 + stack-persistent-2.11.yaml.lock | 7 +++++++ stack.yaml | 2 +- stack.yaml.lock | 8 +++---- 18 files changed, 108 insertions(+), 49 deletions(-) diff --git a/package.yaml b/package.yaml index 98811348..6394d505 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: pantry -version: 0.8.0 +version: 0.8.1 synopsis: Content addressable Haskell package management description: Please see the README on GitHub at category: Development @@ -53,7 +53,7 @@ dependencies: - tar-conduit - time - unix-compat -- hpack >= 0.31.2 +- hpack >= 0.35.1 - yaml - zip-archive - text-metrics diff --git a/pantry.cabal b/pantry.cabal index cf357d40..e1691f7b 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.0 +version: 0.8.1 synopsis: Content addressable Haskell package management description: Please see the README on GitHub at category: Development @@ -69,7 +69,7 @@ library , filelock , generic-deriving , hackage-security - , hpack >=0.31.2 + , hpack >=0.35.1 , http-client , http-client-tls , http-conduit @@ -150,7 +150,7 @@ test-suite spec , generic-deriving , hackage-security , hedgehog - , hpack >=0.31.2 + , hpack >=0.35.1 , hspec , http-client , http-client-tls diff --git a/src/Pantry.hs b/src/Pantry.hs index 9218969d..1b4e5969 100644 --- a/src/Pantry.hs +++ b/src/Pantry.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE LambdaCase #-} -- | Content addressable Haskell package management, providing for -- secure, reproducible acquisition of Haskell package contents and -- metadata. @@ -188,6 +190,9 @@ module Pantry import Database.Persist (entityKey) import RIO +#if !MIN_VERSION_rio(0,1,17) +import Data.Bifunctor (bimap) +#endif import Conduit import Control.Arrow (right) import Control.Monad.State.Strict (State, execState, get, modify') @@ -227,6 +232,23 @@ import Pantry.HTTP import Data.Char (isHexDigit) import Data.Time (getCurrentTime, diffUTCTime) +import Data.Yaml.Include (decodeFileWithWarnings) +import Hpack.Yaml (formatWarning) +import Hpack.Error (formatHpackError) + +decodeYaml :: FilePath -> IO (Either String ([String], Value)) +decodeYaml file = do + bimap displayException (first formatWarnings) <$> decodeFileWithWarnings file + where + formatWarnings = map (formatWarning file) + +formatYamlParseError :: FilePath -> Yaml.ParseException -> String +formatYamlParseError file e = + "In respect of an Hpack defaults file:\n" + <> file + <> ":\n\n" + <> displayException e + -- | Create a new 'PantryConfig' with the given settings. -- -- For something easier to use in simple cases, see 'runPantryApp'. @@ -741,15 +763,18 @@ hpack progName pkgDir = do he <- view $ pantryConfigL.to pcHpackExecutable case he of - HpackBundled -> do - r <- catchAny - ( liftIO - $ Hpack.hpackResult + HpackBundled -> + liftIO + ( Hpack.hpackResultWithError $ mHpackProgName + $ Hpack.setDecode decodeYaml + $ Hpack.setFormatYamlParseError formatYamlParseError $ Hpack.setTarget (toFilePath hpackFile) Hpack.defaultOptions - ) - ( throwIO . HpackLibraryException hpackFile ) + ) + >>= \ case + Left err -> throwIO (HpackLibraryException hpackFile $ formatHpackError (fromMaybe "hpack" progName) err) + Right r -> do forM_ (Hpack.resultWarnings r) (logWarn . fromString) let cabalFile = fromString . Hpack.resultCabalFile $ r case Hpack.resultStatus r of diff --git a/src/Pantry/Types.hs b/src/Pantry/Types.hs index 45fd914d..81a1979b 100644 --- a/src/Pantry/Types.hs +++ b/src/Pantry/Types.hs @@ -970,7 +970,7 @@ data PantryException | MigrationFailure !Text !(Path Abs File) !SomeException | InvalidTreeFromCasa !BlobKey !ByteString | ParseSnapNameException !Text - | HpackLibraryException !(Path Abs File) !SomeException + | HpackLibraryException !(Path Abs File) !String | HpackExeException !FilePath !(Path Abs Dir) !SomeException deriving Typeable @@ -1084,12 +1084,12 @@ instance Display PantryException where <> "Specified snapshot as file path with " <> displayShow t <> ", but not reading from a local file" - display (InvalidSnapshot loc e) = + display (InvalidSnapshot loc err) = "Error: [S-775]\n" <> "Exception while reading snapshot from " <> display loc <> ":\n" - <> displayShow e + <> displayShow err display (MismatchedPackageMetadata loc pm mtreeKey foundIdent) = "Error: [S-427]\n" <> "Mismatched package metadata for " @@ -1112,12 +1112,12 @@ instance Display PantryException where <> display mismatchExpected <> ", actual: " <> display mismatchActual - display (Couldn'tParseSnapshot sl e) = + display (Couldn'tParseSnapshot sl err) = "Error: [S-645]\n" <> "Couldn't parse snapshot from " <> display sl <> ": " - <> fromString e + <> fromString err display (WrongCabalFileName pl sfp name) = "Error: [S-575]\n" <> "Wrong cabal file name for package " @@ -1180,12 +1180,12 @@ instance Display PantryException where <> fromString fp <> ": " <> displayShow x - display (UnsupportedTarball loc e) = + display (UnsupportedTarball loc err) = "Error: [S-760]\n" <> "Unsupported tarball from " <> display loc <> ": " - <> display e + <> display err display (NoHackageCryptographicHash ident) = "Error: [S-922]\n" <> "No cryptographic hash found for Hackage package " @@ -1266,7 +1266,7 @@ instance Display PantryException where <> foldMap (\loc -> "- " <> display loc <> "\n") locs ) pairs' - display (MigrationFailure desc fp ex) = + display (MigrationFailure desc fp err) = "Error: [S-536]\n" <> "Encountered error while migrating database " <> display desc @@ -1274,27 +1274,27 @@ instance Display PantryException where <> fromString (toFilePath fp) <> ":" <> "\n " - <> displayShow ex + <> displayShow err display (ParseSnapNameException t) = "Error: [S-994]\n" <> "Invalid snapshot name: " <> display t - display (HpackLibraryException file e) = + display (HpackLibraryException file err) = "Error: [S-305]\n" <> "Failed to generate a Cabal file using the Hpack library on file:\n" <> fromString (toFilePath file) <> "\n\n" - <> "The exception encountered was:\n\n" - <> fromString (show e) - display (HpackExeException fp dir e) = + <> "The error encountered was:\n\n" + <> fromString err + display (HpackExeException fp dir err) = "Error: [S-720]\n" <> "Failed to generate a Cabal file using the Hpack executable:\n" <> fromString fp <> "in directory: " <> fromString (toFilePath dir) <> "\n\n" - <> "The exception encountered was:\n\n" - <> fromString (show e) + <> "The error encountered was:\n\n" + <> fromString (show err) data FuzzyResults = FRNameNotFound ![PackageName] diff --git a/stack-cabal-3.4.yaml b/stack-cabal-3.4.yaml index da962f70..be10c408 100644 --- a/stack-cabal-3.4.yaml +++ b/stack-cabal-3.4.yaml @@ -4,6 +4,7 @@ resolver: lts-18.28 extra-deps: # lts-18.28 provides Cabal-3.2.1.0 - Cabal-3.4.0.0 +- hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 ghc-options: "$locals": -fhide-source-paths diff --git a/stack-cabal-3.4.yaml.lock b/stack-cabal-3.4.yaml.lock index c0524753..f517a616 100644 --- a/stack-cabal-3.4.yaml.lock +++ b/stack-cabal-3.4.yaml.lock @@ -11,6 +11,13 @@ packages: size: 45845 original: hackage: Cabal-3.4.0.0 +- completed: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 + pantry-tree: + sha256: 514f0311eff442ab83ef3c2db456857f360ea173c17df133e575f50915e02da0 + size: 3675 + original: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 snapshots: - completed: sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68 diff --git a/stack-ghc-8.6.5.yaml b/stack-ghc-8.6.5.yaml index f34e9a67..7693a2a8 100644 --- a/stack-ghc-8.6.5.yaml +++ b/stack-ghc-8.6.5.yaml @@ -3,7 +3,7 @@ resolver: lts-14.27 extra-deps: - Cabal-3.0.0.0 -- hpack-0.35.0 +- hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 - casa-client-0.0.1 - casa-types-0.0.1 diff --git a/stack-ghc-8.6.5.yaml.lock b/stack-ghc-8.6.5.yaml.lock index 0d0a3ce3..2ce57a39 100644 --- a/stack-ghc-8.6.5.yaml.lock +++ b/stack-ghc-8.6.5.yaml.lock @@ -12,12 +12,12 @@ packages: original: hackage: Cabal-3.0.0.0 - completed: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 pantry-tree: - sha256: f143c1cb86d6ae954be5b3cc04629fb00631290c8eb9e3c795f65e10d6ccf220 - size: 3615 + sha256: 514f0311eff442ab83ef3c2db456857f360ea173c17df133e575f50915e02da0 + size: 3675 original: - hackage: hpack-0.35.0 + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 - completed: hackage: casa-client-0.0.1@sha256:7c254d0f21fa96c1e64fff027a479ba2e93b2d53bb1938b62dc63dc6018f12a1,892 pantry-tree: diff --git a/stack-ghc-8.8.4.yaml b/stack-ghc-8.8.4.yaml index 1162d189..24fb86cd 100644 --- a/stack-ghc-8.8.4.yaml +++ b/stack-ghc-8.8.4.yaml @@ -3,7 +3,7 @@ resolver: lts-16.31 extra-deps: - Cabal-3.0.0.0 -- hpack-0.35.0 +- hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 ghc-options: "$locals": -fhide-source-paths diff --git a/stack-ghc-8.8.4.yaml.lock b/stack-ghc-8.8.4.yaml.lock index e671be98..140c34e6 100644 --- a/stack-ghc-8.8.4.yaml.lock +++ b/stack-ghc-8.8.4.yaml.lock @@ -12,12 +12,12 @@ packages: original: hackage: Cabal-3.0.0.0 - completed: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 pantry-tree: - sha256: f143c1cb86d6ae954be5b3cc04629fb00631290c8eb9e3c795f65e10d6ccf220 - size: 3615 + sha256: 514f0311eff442ab83ef3c2db456857f360ea173c17df133e575f50915e02da0 + size: 3675 original: - hackage: hpack-0.35.0 + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 snapshots: - completed: sha256: 637fb77049b25560622a224845b7acfe81a09fdb6a96a3c75997a10b651667f6 diff --git a/stack-ghc-9.2.5.yaml b/stack-ghc-9.2.5.yaml index c0c14536..8ecaa84a 100644 --- a/stack-ghc-9.2.5.yaml +++ b/stack-ghc-9.2.5.yaml @@ -1,5 +1,8 @@ # GHC 9.2.5 -resolver: lts-20.0 +resolver: lts-20.4 + +extra-deps: +- hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 ghc-options: "$locals": -fhide-source-paths diff --git a/stack-ghc-9.2.5.yaml.lock b/stack-ghc-9.2.5.yaml.lock index c4546456..bb6b7a19 100644 --- a/stack-ghc-9.2.5.yaml.lock +++ b/stack-ghc-9.2.5.yaml.lock @@ -3,10 +3,17 @@ # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files -packages: [] +packages: +- completed: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 + pantry-tree: + sha256: 514f0311eff442ab83ef3c2db456857f360ea173c17df133e575f50915e02da0 + size: 3675 + original: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 snapshots: - completed: - sha256: a2cbcd2f37010a64c4ef74c21fd7e55982a07b49840d2bed306f9bac9981a9c3 - size: 648420 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/0.yaml - original: lts-20.0 + sha256: 3770dfd79f5aed67acdcc65c4e7730adddffe6dba79ea723cfb0918356fc0f94 + size: 648660 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/4.yaml + original: lts-20.4 diff --git a/stack-ghc-9.4.3.yaml b/stack-ghc-9.4.3.yaml index cba1a76d..3eb53d07 100644 --- a/stack-ghc-9.4.3.yaml +++ b/stack-ghc-9.4.3.yaml @@ -2,7 +2,8 @@ resolver: nightly-2022-12-09 extra-deps: -- hackage-security-0.6.2.3 +- hackage-security-0.6.2.3@sha256:64fc60f3f4d02047c54956b6976c0e4fc72722891c6875ab10d95359bc00355a,12649 +- hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 flags: mintty: diff --git a/stack-ghc-9.4.3.yaml.lock b/stack-ghc-9.4.3.yaml.lock index 082cb5f8..7ef75b20 100644 --- a/stack-ghc-9.4.3.yaml.lock +++ b/stack-ghc-9.4.3.yaml.lock @@ -10,7 +10,14 @@ packages: sha256: f9df7c76d920dbabb0f89fd7b9099f8f80f022dcb6e9cf8ae089c6de274c41d4 size: 4034 original: - hackage: hackage-security-0.6.2.3 + hackage: hackage-security-0.6.2.3@sha256:64fc60f3f4d02047c54956b6976c0e4fc72722891c6875ab10d95359bc00355a,12649 +- completed: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 + pantry-tree: + sha256: 514f0311eff442ab83ef3c2db456857f360ea173c17df133e575f50915e02da0 + size: 3675 + original: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 snapshots: - completed: sha256: b77e2c2b7988ed34cd317c01eb1958a8b8c234c3cc17e44077616c212959bed0 diff --git a/stack-persistent-2.11.yaml b/stack-persistent-2.11.yaml index 4f91251f..fc00e2c3 100644 --- a/stack-persistent-2.11.yaml +++ b/stack-persistent-2.11.yaml @@ -2,6 +2,7 @@ resolver: lts-16.31 extra-deps: +- hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 - persistent-2.11.0.4@rev:0 - persistent-sqlite-2.11.1.0@rev:0 - persistent-template-2.9.1.0@rev:0 diff --git a/stack-persistent-2.11.yaml.lock b/stack-persistent-2.11.yaml.lock index b13d2f02..0990154b 100644 --- a/stack-persistent-2.11.yaml.lock +++ b/stack-persistent-2.11.yaml.lock @@ -4,6 +4,13 @@ # https://docs.haskellstack.org/en/stable/lock_files packages: +- completed: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 + pantry-tree: + sha256: 514f0311eff442ab83ef3c2db456857f360ea173c17df133e575f50915e02da0 + size: 3675 + original: + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 - completed: hackage: persistent-2.11.0.4@sha256:a55a9a30d663407d77e2ea0e65b1e29e3aa2ecf531d7d758ded31c415875e216,4735 pantry-tree: diff --git a/stack.yaml b/stack.yaml index 8094e228..7430041b 100644 --- a/stack.yaml +++ b/stack.yaml @@ -2,7 +2,7 @@ resolver: lts-18.28 extra-deps: -- hpack-0.35.0 +- hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 ghc-options: "$locals": -fhide-source-paths diff --git a/stack.yaml.lock b/stack.yaml.lock index 9b70b2d6..8455f4b7 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -5,12 +5,12 @@ packages: - completed: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 pantry-tree: - sha256: f143c1cb86d6ae954be5b3cc04629fb00631290c8eb9e3c795f65e10d6ccf220 - size: 3615 + sha256: 514f0311eff442ab83ef3c2db456857f360ea173c17df133e575f50915e02da0 + size: 3675 original: - hackage: hpack-0.35.0 + hackage: hpack-0.35.1@sha256:ef816234cbc7b52b0a6c55f7e904b6bc5292b8dd8f2d81ffcbcbc69ab80d75e5,4762 snapshots: - completed: sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68