@@ -54,6 +54,28 @@ data ParseException = NonScalarKey
54 deriving (Show, Typeable)
54 deriving (Show, Typeable)
55instance Exception ParseException
55instance Exception ParseException
57+-- | Alternative to 'show' to display a 'ParseException' on the screen.
58+-- Instead of displaying the data constructors applied to their arguments,
59+-- a more textual output is returned. For example, instead of printing:
61+-- > AesonException "The key \"foo\" was not found"
63+-- It looks more pleasant to print:
65+-- > Aeson exception: The key "foo" was not found
67+prettyPrintParseException :: ParseException -> String
68+prettyPrintParseException NonScalarKey = "Non scalar key"
69+prettyPrintParseException InvalidYaml mye =
71+ Just ye -> "Invalid yaml: " ++ show ye
73+prettyPrintParseException (AesonException e) =
74+ "Aeson exception: " ++ e
75+prettyPrintParseException pe = show pe
76+-- TODO: This is just a stab at the implementation.
77+-- If the idea is likely to be merged, I can develop it further.
57newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) }
79newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) }
58instance Monad m => Functor (PErrorT m) where
80instance Monad m => Functor (PErrorT m) where
59 fmap = liftM
81 fmap = liftM