on master help sign in
Make it compile with prettyPrintParseException, export this function from Data.Yaml, and implement displayException for recent versions o base.
commit91203d24e351f34703e3c8f4c5757bba189e20e7 authorDaniel Díaz <dhelta.diaz@gmail.com> dateSat 18 Apr 2015, 10:22 (12 years ago) parent8c1b69d
2 files changed+11−4
Data/Yaml.hs+1 Data/Yaml/Internal.hs+10−4
Data/Yaml.hs+1
@@ -24,6 +24,7 @@ module Data.Yaml
2424 , Object
2525 , Array
2626 , ParseException(..)
27+ , prettyPrintParseException
2728 , YamlException (..)
2829 , YamlMark (..)
2930 -- * Constructors and accessors
Data/Yaml/Internal.hs+10−4
@@ -5,6 +5,7 @@
55module Data.Yaml.Internal
66 (
77 ParseException(..)
8+ , prettyPrintParseException
89 , parse
910 , decodeHelper
1011 , decodeHelper_
@@ -52,7 +53,11 @@ data ParseException = NonScalarKey
5253 | NonStringKeyAlias Y.AnchorName Value
5354 | CyclicIncludes
5455 deriving (Show, Typeable)
55−instance Exception ParseException
56+
57+instance Exception ParseException where
58+#if MIN_VERSION_base(4, 8, 0)
59+ displayException = prettyPrintParseException
60+#endif
5661
5762-- | Alternative to 'show' to display a 'ParseException' on the screen.
5863-- Instead of displaying the data constructors applied to their arguments,
@@ -66,15 +71,16 @@ instance Exception ParseException
6671--
6772prettyPrintParseException :: ParseException -> String
6873prettyPrintParseException NonScalarKey = "Non scalar key"
69−prettyPrintParseException InvalidYaml mye =
74+prettyPrintParseException (InvalidYaml mye) =
7075 case mye of
7176 Just ye -> "Invalid yaml: " ++ show ye
7277 _ -> "Invalid yaml"
7378prettyPrintParseException (AesonException e) =
7479 "Aeson exception: " ++ e
80+prettyPrintParseException CyclicIncludes = "Cyclic includes"
81+prettyPrintParseException (OtherParseException e) =
82+ "Parse exception: " ++ show e
7583prettyPrintParseException 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.
7884
7985newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) }
8086instance Monad m => Functor (PErrorT m) where