@@ -5,6 +5,7 @@
5module Data.Yaml.Internal
5module Data.Yaml.Internal
7 ParseException(..)
7 ParseException(..)
8+ , prettyPrintParseException
9 , decodeHelper
10 , decodeHelper
10 , decodeHelper_
11 , decodeHelper_
@@ -52,7 +53,45 @@ data ParseException = NonScalarKey
52 | NonStringKeyAlias Y.AnchorName Value
53 | NonStringKeyAlias Y.AnchorName Value
53 | CyclicIncludes
54 | CyclicIncludes
54 deriving (Show, Typeable)
55 deriving (Show, Typeable)
55−instance Exception ParseException
57+instance Exception ParseException where
58+#if MIN_VERSION_base(4, 8, 0)
59+ displayException = prettyPrintParseException
62+-- | Alternative to 'show' to display a 'ParseException' on the screen.
63+-- Instead of displaying the data constructors applied to their arguments,
64+-- a more textual output is returned. For example, instead of printing:
66+-- > AesonException "The key \"foo\" was not found"
68+-- It looks more pleasant to print:
70+-- > Aeson exception: The key "foo" was not found
72+prettyPrintParseException :: ParseException -> String
73+prettyPrintParseException NonScalarKey = "Non scalar key"
74+prettyPrintParseException (UnknownAlias n) =
75+ "Unknown alias: " ++ n
76+prettyPrintParseException (UnexpectedEvent r e) = unlines
77+ [ "Unexpected event:"
78+ , " Received: " ++ maybe "None" show r
79+ , " Expected: " ++ maybe "None" show e
81+prettyPrintParseException (InvalidYaml mye) =
83+ Just ye -> "Invalid yaml: " ++ show ye
85+prettyPrintParseException (AesonException e) =
86+ "Aeson exception: " ++ e
87+prettyPrintParseException (OtherParseException e) =
88+ "Parse exception: " ++ show e
89+prettyPrintParseException (NonStringKeyAlias n v) = unlines
90+ [ "Non-string key alias:"
91+ , " Anchor name: " ++ n
92+ , " Value: " ++ show v
94+prettyPrintParseException CyclicIncludes = "Cyclic includes"
57newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) }
96newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) }
58instance Monad m => Functor (PErrorT m) where
97instance Monad m => Functor (PErrorT m) where