From 8ffd58b2f1c5c6733f35bf50adf0b59749457f07 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Sat, 20 Jul 2024 09:06:05 -0400 Subject: [PATCH] Make GHCComponent match the command name and improve the error message --- code/hsec-core/src/Security/Advisories/Core/Advisory.hs | 8 ++++---- code/hsec-tools/src/Security/Advisories/Format.hs | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/code/hsec-core/src/Security/Advisories/Core/Advisory.hs b/code/hsec-core/src/Security/Advisories/Core/Advisory.hs index a49f0c7..92ef84d 100644 --- a/code/hsec-core/src/Security/Advisories/Core/Advisory.hs +++ b/code/hsec-core/src/Security/Advisories/Core/Advisory.hs @@ -57,12 +57,12 @@ 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" @@ -70,12 +70,12 @@ ghcComponentToText c = case c of 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 diff --git a/code/hsec-tools/src/Security/Advisories/Format.hs b/code/hsec-tools/src/Security/Advisories/Format.hs index a2fff80..b5f8007 100644 --- a/code/hsec-tools/src/Security/Advisories/Format.hs +++ b/code/hsec-tools/src/Security/Advisories/Format.hs @@ -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