on master help sign in
add records for error handling
6d40221Boris Lykah
Text/Libyaml.hs+10−4
@@ -23,8 +23,9 @@ module Text.Libyaml
23 , decode
23 , decode
24 , encodeFile
24 , encodeFile
25 , decodeFile
25 , decodeFile
26− -- * Exception
26+ -- * Error handling
27 , YamlException (..)
27 , YamlException (..)
28+ , YamlMark (..)
28 ) where
29 ) where
29
30
30import qualified Data.ByteString.Internal as B
31import qualified Data.ByteString.Internal as B
@@ -533,7 +534,8 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
533 index <- c_get_parser_error_index parser
534 index <- c_get_parser_error_index parser
534 line <- c_get_parser_error_line parser
535 line <- c_get_parser_error_line parser
535 column <- c_get_parser_error_column parser
536 column <- c_get_parser_error_column parser
537+ let problemMark = YamlMark (fromIntegral index) (fromIntegral line) (fromIntegral column)
536− return $ Left $ YamlParseException problem context (fromIntegral index, fromIntegral line, fromIntegral column)
538+ return $ Left $ YamlParseException problem context problemMark
537 else Right <$> getEvent er
539 else Right <$> getEvent er
538
540
539encode :: MonadResource m => GSink Event m ByteString
541encode :: MonadResource m => GSink Event m ByteString
@@ -593,8 +595,12 @@ runEmitter allocI closeI =
593 loop
595 loop
594 close u = liftIO $ closeI u a
596 close u = liftIO $ closeI u a
595
597
598+-- | The pointer position
599+data YamlMark = YamlMark { yamlIndex :: Int, yamlLine :: Int, yamlColumn :: Int }
600+ deriving Show
601+
596data YamlException = YamlException String
602data YamlException = YamlException String
597 -- | problem, context, index, position line, position column
603 -- | problem, context, index, position line, position column
598− | YamlParseException String String (Int, Int, Int)
604+ | YamlParseException { yamlProblem :: String, yamlContext :: String, yamlProblemMark :: YamlMark }
599 deriving (Show, Typeable)
605 deriving (Show, Typeable)
600−instance Exception YamlException
606+instance Exception YamlException