pantry 0.8.0 → 0.8.1
raw patch · 4 files changed
+57/−27 lines, 4 filesdep ~Cabaldep ~hpackPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: Cabal, hpack
API changes (from Hackage documentation)
- Pantry: HpackLibraryException :: !Path Abs File -> !SomeException -> PantryException
+ Pantry: HpackLibraryException :: !Path Abs File -> !String -> PantryException
Files
- ChangeLog.md +4/−0
- pantry.cabal +3/−3
- src/Pantry.hs +31/−6
- src/Pantry/Types.hs +19/−18
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for pantry +## v0.8.1 + +* Support `hpack-0.35.1`, and prettier `HpackLibraryException` error messages. + ## v0.8.0 * `findOrGenerateCabalFile`, `loadCabalFilePath`, `loadCabalFile` and
pantry.cabal view
@@ -5,7 +5,7 @@ -- 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 <https://github.com/commercialhaskell/pantry#readme> category: Development @@ -69,7 +69,7 @@ , filelock , generic-deriving , hackage-security - , hpack >=0.31.2 + , hpack >=0.35.1 , http-client , http-client-tls , http-conduit @@ -150,7 +150,7 @@ , generic-deriving , hackage-security , hedgehog - , hpack >=0.31.2 + , hpack >=0.35.1 , hspec , http-client , http-client-tls
src/Pantry.hs view
@@ -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 @@ 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 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 @@ 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
src/Pantry/Types.hs view
@@ -970,7 +970,7 @@ | 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 @@ -1037,13 +1037,14 @@ <> fold (intersperse ", " (map display sfps)) display (MismatchedCabalName fp name) = "Error: [S-910]\n" - <> "cabal file path " + <> "The Cabal file:\n" <> fromString (toFilePath fp) - <> " does not match the package name it defines.\n" + <> "\nis not named after the package that it defines.\n" <> "Please rename the file to: " <> fromString (packageNameString name) <> ".cabal\n" - <> "For more information, see: https://github.com/commercialhaskell/stack/issues/317" + <> "Hackage rejects packages where the first part of the Cabal file name " + <> "is not the package name." display (NoCabalFileFound dir) = "Error: [S-636]\n" <> "Stack looks for packages in the directories configured in\n" @@ -1083,12 +1084,12 @@ <> "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 " @@ -1111,12 +1112,12 @@ <> 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 " @@ -1179,12 +1180,12 @@ <> 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 " @@ -1265,7 +1266,7 @@ <> 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 @@ -1273,27 +1274,27 @@ <> 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]