From 70f40779bca75d54c6b5709dfe3455cbe1df11ac Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 27 Jul 2024 11:12:16 +1000 Subject: [PATCH] improve GHCComponent parse errors --- code/hsec-tools/src/Security/Advisories/Format.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/code/hsec-tools/src/Security/Advisories/Format.hs b/code/hsec-tools/src/Security/Advisories/Format.hs index b5f8007..19037c5 100644 --- a/code/hsec-tools/src/Security/Advisories/Format.hs +++ b/code/hsec-tools/src/Security/Advisories/Format.hs @@ -139,8 +139,17 @@ instance Toml.ToTable AdvisoryMetadata where instance Toml.FromValue GHCComponent where fromValue v = case v of Toml.Text' _ n - | Just c <- ghcComponentFromText n -> pure c - _ -> Toml.failAt (Toml.valueAnn v) $ T.unpack $ "Invalid component, expected " <> T.intercalate "|" componentNames + | Just c <- ghcComponentFromText n + -> pure c + | otherwise + -> Toml.failAt (Toml.valueAnn v) $ + "Invalid ghc-component '" + <> T.unpack n + <> "', expected " + <> T.unpack (T.intercalate "|" componentNames) + _ -> Toml.failAt (Toml.valueAnn v) $ + "Non-text ghc-component, expected" + <> T.unpack (T.intercalate "|" componentNames) where componentNames = map ghcComponentToText [minBound..maxBound]