diff --git a/cabal-audit.cabal b/cabal-audit.cabal index 671773c..dae34a0 100644 --- a/cabal-audit.cabal +++ b/cabal-audit.cabal @@ -69,7 +69,7 @@ library , filepath , fused-effects , hsec-core ^>=0.1 - , hsec-tools ^>=0.1 + , hsec-tools ^>=0.2 , http-client , kan-extensions , optparse-applicative diff --git a/src/Distribution/Audit.hs b/src/Distribution/Audit.hs index 7828214..91f4ac2 100644 --- a/src/Distribution/Audit.hs +++ b/src/Distribution/Audit.hs @@ -1,5 +1,3 @@ -{-# OPTIONS_GHC -Wno-orphans #-} - -- | provides the @cabal-audit@ plugin which works as follows: -- -- 1. parse command line arguments to pass on to cabal to build @@ -22,7 +20,6 @@ import Data.Foldable (for_) import Data.Functor.Identity (Identity (runIdentity)) import Data.List qualified as List import Data.Map qualified as M -import Data.Monoid (Endo (..)) import Data.String (IsString (fromString)) import Data.Text (Text) import Data.Text qualified as T @@ -59,54 +56,15 @@ data AuditException CabalException {reason :: String, cabalException :: SomeException} deriving stock (Show, Generic) -type DString = Endo String - -instance (IsString a, Semigroup a) => IsString (Endo a) where - fromString s = Endo (<> fromString s) - -runDString :: DString -> String -runDString = flip appEndo [] - -eshow :: Show a => a -> DString -eshow = Endo . shows - -etxt :: Text -> Endo String -etxt = fromString . T.unpack - -prettyParseAdvisoryError :: ParseAdvisoryError -> DString -prettyParseAdvisoryError = \case - MarkdownError parseError txt -> - mconcat - [ "error parsing commonmark markdown: \n\n" - , "\t" <> eshow parseError <> "\n" - , "\t" <> etxt txt <> "\n" - ] - MarkdownFormatError txt -> - mconcat - [ "problem with the structure of the markdown:" - , "\t" <> etxt txt - ] - TomlError _ txt -> - mconcat - [ "couldn't parse toml:" - , "\t" <> etxt txt - ] - AdvisoryError _ txt -> - mconcat - [ "problems while parsing advisories:" - , "\t" <> etxt txt - ] - instance Exception AuditException where displayException = \case ListAdvisoryValidationError dir errs -> - runDString $ - mconcat - [ "Listing the advisories in directory " - , fromString dir - , " failed with: \n" - , mconcat $ prettyParseAdvisoryError <$> errs - ] + mconcat + [ "Listing the advisories in directory " + , dir + , " failed with: \n" + , mconcat $ displayException <$> errs + ] CabalException ctx (SomeException ex) -> "cabal failed while " <> ctx