@@ -4,8 +4,6 @@
44{-# LANGUAGE FlexibleContexts #-}
55{-# LANGUAGE MultiParamTypeClasses #-}
66
7−{-# INCLUDE <yaml.h> #-}
8−{-# INCLUDE <helper.h> #-}
97module Data.Object.Yaml.Lib
108 ( withEmitter
119 , emitEvents
@@ -29,7 +27,8 @@ import Data.Convertible.Text
2927import Control.Applicative
3028
3129import Data.Object.Yaml.Internal
32−import Control.Exception (throwIO)
30+import Control.Exception (throwIO, Exception)
31+import Data.Typeable (Typeable)
3332
3433data ParserStruct
3534type Parser = Ptr ParserStruct
@@ -327,7 +326,7 @@ foreign import ccall unsafe "yaml_mapping_end_event_initialize"
327326
328327toEventRaw :: Event -> (EventRaw -> IO a) -> IO a
329328toEventRaw e f = withEventRaw $ \er -> do
330− case e of
329+ ret <- case e of
331330 EventStreamStart ->
332331 c_yaml_stream_start_event_initialize
333332 er
@@ -380,8 +379,13 @@ toEventRaw e f = withEventRaw $ \er -> do
380379 c_yaml_mapping_end_event_initialize er
381380 EventAlias -> error "toEventRaw: EventAlias not supported"
382381 EventNone -> error "toEventRaw: EventNone not supported"
382+ unless (ret == 1) $ failure $ ToEventRawException ret
383383 f er
384384
385+newtype ToEventRawException = ToEventRawException CInt
386+ deriving (Show, Typeable)
387+instance Exception ToEventRawException
388+
385389encode :: MonadFailure YamlException m
386390 => [Event]
387391 -> IO (m B.ByteString)