Skip to content

Commit

Permalink
[chore] some fixes and simplification after applying haskell/security…
Browse files Browse the repository at this point in the history
  • Loading branch information
MangoIV committed May 31, 2024
1 parent 84ddd18 commit 2eaae7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cabal-audit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 6 additions & 48 deletions src/Distribution/Audit.hs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2eaae7e

Please sign in to comment.