Skip to content

Commit b04d938

Browse files
glguyblackheaven
authored andcommitted
switch to more structured toml validation errors
1 parent 0a28007 commit b04d938

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

code/hsec-tools/hsec-tools.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ library
5050
containers >= 0.6 && < 0.7,
5151
commonmark ^>= 0.2.2,
5252
aeson >= 2.0.1.0 && < 3,
53-
toml-parser ^>=1.2.1.0,
53+
toml-parser ^>=1.3.0.0,
5454
pandoc-types >= 1.22 && < 2,
5555
pathwalk >= 0.3,
5656
parsec >= 3 && < 4,

code/hsec-tools/src/Security/Advisories/Parse.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import qualified Commonmark.Parser as Commonmark
3535
import Commonmark.Types (HasAttributes(..), IsBlock(..), IsInline(..), Rangeable(..), SourceRange(..))
3636
import Commonmark.Pandoc (Cm(unCm))
3737
import qualified Toml
38+
import qualified Toml.Pretty as Toml
3839
import qualified Toml.FromValue as Toml
3940
import qualified Toml.FromValue.Matcher as Toml
4041
import qualified Toml.ToValue as Toml
@@ -77,7 +78,7 @@ data ParseAdvisoryError
7778
= MarkdownError Commonmark.ParseError T.Text
7879
| MarkdownFormatError T.Text
7980
| TomlError String T.Text
80-
| AdvisoryError [String] T.Text
81+
| AdvisoryError [Toml.MatchMessage] T.Text
8182
deriving stock (Eq, Show, Generic)
8283

8384
-- | The main parsing function. 'OutOfBandAttributes' are handled
@@ -126,10 +127,10 @@ parseAdvisory policy attrs raw = do
126127
(Commonmark.commonmark "input" raw :: Either Commonmark.ParseError (Html ()))
127128

128129
case parseAdvisoryTable attrs policy doc summary details html table of
129-
Toml.Failure es -> Left (AdvisoryError es (T.pack (unlines es)))
130+
Toml.Failure es -> Left (AdvisoryError es (T.pack (unlines (map Toml.prettyMatchMessage es))))
130131
Toml.Success warnings adv
131132
| null warnings -> pure adv
132-
| otherwise -> Left (AdvisoryError warnings (T.pack (unlines warnings))) -- treat warnings as errors
133+
| otherwise -> Left (AdvisoryError warnings (T.pack (unlines (map Toml.prettyMatchMessage warnings)))) -- treat warnings as errors
133134

134135
where
135136
firstPretty
@@ -154,7 +155,7 @@ parseAdvisoryTable
154155
-> T.Text -- ^ details
155156
-> T.Text -- ^ rendered HTML
156157
-> Toml.Table
157-
-> Toml.Result Advisory
158+
-> Toml.Result Toml.MatchMessage Advisory
158159
parseAdvisoryTable oob policy doc summary details html tab =
159160
Toml.runMatcher $
160161
do fm <- Toml.fromValue (Toml.Table tab)

0 commit comments

Comments
 (0)