@@ -18,17 +18,27 @@ failure = D4.Failure
1818 , D4._failureOffendingData = AP.Pointer [AP.Token "0"]
1919 }
2020
21−subsetOfData :: Value
22−subsetOfData =
23− -- This is the only really interesting part of this example. To resolve the
24− -- pointer to the part of the data that triggered the validation failure we
25− -- have to have hjsonpointer in our build-depends and use 'AP.resolve'.
21+example :: IO ()
22+example =
23+ -- 'D4.Failure's contain the sequence of embedded validators that caused
24+ -- the invalidation, the contents of the final validator in that sequence,
25+ -- and a JSON Pointer to the subset of data that caused validation to fail.
26+ --
27+ -- They don't actually contain that subset of data, since it can be derived
28+ -- from the original data and the JSON Pointer.
29+ --
30+ -- If you want to display the invalid subset of the data here's how you
31+ -- resolve the JSON Pointer ('D4._failureOffendingData') against the
32+ -- original data.
33+ --
34+ -- NOTE: You have to have hjsonpointer in your build-depends.
2635 case AP.resolve (D4._failureOffendingData failure) badData of
2736 Left _ -> error "Couldn't resolve pointer."
28− Right v -> v
37+ Right _ -> putStrLn "Success." -- We could feed the 'Right' value into
38+ -- 'msg' if we wanted to display it.
2939
30−example :: IO ()
31−example = putStrLn . unlines $
40+msg :: Value -> String
41+msg subsetOfData = unlines
3242 [ "Invalid data. Here's the sequence of validators that caught it:"
3343 , ""
3444 , " " <> show (D4._failureValidatorsCalled failure)