Skip to content

Commit

Permalink
Make GHCComponent match the command name and improve the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray authored and frasertweedale committed Jul 30, 2024
1 parent b3b9e82 commit 8ffd58b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions code/hsec-core/src/Security/Advisories/Core/Advisory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ data GHCComponent = GHCCompiler | GHCi | GHCRTS | GHCPkg | RunGHC | IServ | HP2P

ghcComponentToText :: GHCComponent -> Text
ghcComponentToText c = case c of
GHCCompiler -> "compiler"
GHCCompiler -> "ghc"
GHCi -> "ghci"
GHCRTS -> "rts"
GHCPkg -> "ghc-pkg"
RunGHC -> "runghc"
IServ -> "iserv"
IServ -> "ghc-iserv"
HP2PS -> "hp2ps"
HPC -> "hpc"
HSC2HS -> "hsc2hs"
Haddock -> "haddock"

ghcComponentFromText :: Text -> Maybe GHCComponent
ghcComponentFromText c = case c of
"compiler" -> Just GHCCompiler
"ghc" -> Just GHCCompiler
"ghci" -> Just GHCi
"rts" -> Just GHCRTS
"ghc-pkg" -> Just GHCPkg
"runghc" -> Just RunGHC
"iserv" -> Just IServ
"ghc-iserv" -> Just IServ
"hp2ps" -> Just HP2PS
"hpc" -> Just HPC
"hsc2hs" -> Just HSC2HS
Expand Down
4 changes: 3 additions & 1 deletion code/hsec-tools/src/Security/Advisories/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ instance Toml.FromValue GHCComponent where
fromValue v = case v of
Toml.Text' _ n
| Just c <- ghcComponentFromText n -> pure c
_ -> Toml.failAt (Toml.valueAnn v) "Invalid component, expected compiler|ghci|rts"
_ -> Toml.failAt (Toml.valueAnn v) $ T.unpack $ "Invalid component, expected " <> T.intercalate "|" componentNames
where
componentNames = map ghcComponentToText [minBound..maxBound]

instance Toml.ToValue GHCComponent where
toValue = Toml.Text' () . ghcComponentToText
Expand Down

0 comments on commit 8ffd58b

Please sign in to comment.