@@ -19,6 +19,7 @@ import Data.Aeson.Types hiding (parse)
1919import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
2020import Data.ByteString (ByteString)
2121import qualified Data.Map as Map
22+import Data.Maybe (isNothing)
2223import Control.Exception
2324import Control.Exception.Enclosed
2425import Control.Monad.Trans.State
@@ -79,24 +80,28 @@ prettyPrintParseException :: ParseException -> String
7980prettyPrintParseException pe = case pe of
8081 NonScalarKey -> "Non scalar key"
8182 UnknownAlias anchor -> "Unknown alias `" ++ anchor ++ "`"
82− UnexpectedEvent mbExpected mbUnexpected -> case (mbExpected, mbUnexpected) of
83− (Nothing, Nothing) ->
84− error $ "prettyPrintYamlParseException: Got UnexpectedEvent with two `Nothing`s"
85− (Just expected, Just received) -> unlines
86− [ "Unexpected event: expected"
87− , " " ++ show expected
88− , "but received"
89− , " " ++ show received
90− ]
91− (Just expected, Nothing) -> unlines
92− [ "Expected event"
93− , " " ++ show expected
94− , "but got none"
95− ]
96− (Nothing, Just received) -> unlines
97− [ "Expected no events, but received"
98− , " " ++ show received
99− ]
83+ UnexpectedEvent mbExpected mbUnexpected ->
84+ assert (not (isNothing mbExpected && isNothing mbUnexpected)) $
85+ case (mbExpected, mbUnexpected) of
86+ (Nothing, Nothing) -> unlines
87+ [ "Got UnexpectedEvent with two `Nothing`s, this should never happen."
88+ , "Please report it as a bug at <https://github.com/snoyberg/yaml/>"
89+ ]
90+ (Just expected, Just received) -> unlines
91+ [ "Unexpected event: expected"
92+ , " " ++ show expected
93+ , "but received"
94+ , " " ++ show received
95+ ]
96+ (Just expected, Nothing) -> unlines
97+ [ "Expected event"
98+ , " " ++ show expected
99+ , "but got none"
100+ ]
101+ (Nothing, Just received) -> unlines
102+ [ "Expected no events, but received"
103+ , " " ++ show received
104+ ]
100105 InvalidYaml mbYamlError -> case mbYamlError of
101106 Nothing -> "Unspecified YAML error"
102107 Just yamlError -> case yamlError of