Skip to content

Commit

Permalink
improve GHCComponent parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
frasertweedale committed Jul 30, 2024
1 parent 8ffd58b commit 70f4077
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions code/hsec-tools/src/Security/Advisories/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 70f4077

Please sign in to comment.