@@ -62,10 +62,8 @@ import Data.Aeson
62import Data.Aeson.Types (Pair, parseMaybe, parseEither, Parser)
62import Data.Aeson.Types (Pair, parseMaybe, parseEither, Parser)
63import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
63import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
64import Data.ByteString (ByteString)
64import Data.ByteString (ByteString)
65−import qualified Data.Map as Map
66import System.IO.Unsafe (unsafePerformIO)
65import System.IO.Unsafe (unsafePerformIO)
67−import Control.Exception (try, throwIO, fromException, AsyncException)
66+import Control.Exception
68−import Control.Monad.Trans.State
69import qualified Data.Conduit as C
67import qualified Data.Conduit as C
70import qualified Data.Conduit.List as CL
68import qualified Data.Conduit.List as CL
71import qualified Data.Vector as V
69import qualified Data.Vector as V
@@ -164,8 +162,8 @@ decode :: FromJSON a
164 => ByteString
162 => ByteString
165 -> Maybe a
163 -> Maybe a
166decode bs = unsafePerformIO
164decode bs = unsafePerformIO
167− $ fmap (either (const Nothing) (either (const Nothing) Just))
165+ $ fmap (either (const Nothing) id)
168− $ decodeHelper (Y.decode bs)
166+ $ decodeHelper_ (Y.decode bs)
170decodeFile :: FromJSON a
168decodeFile :: FromJSON a
171 => FilePath
169 => FilePath
@@ -179,24 +177,7 @@ decodeFileEither
179 :: FromJSON a
177 :: FromJSON a
180 => FilePath
178 => FilePath
181 -> IO (Either ParseException a)
179 -> IO (Either ParseException a)
182−decodeFileEither fp = do
180+decodeFileEither = decodeHelper_ . Y.decodeFile
183− x <- try $ runResourceT $ flip evalStateT Map.empty $ Y.decodeFile fp C.$$ parse
186− | Just pe <- fromException e -> return $ Left pe
187− | Just ye <- fromException e -> return $ Left $ InvalidYaml $ Just (ye :: YamlException)
188− | shouldBeCaught e -> return $ Left $ OtherParseException e
189− | otherwise -> throwIO e
191− return $ case parseEither parseJSON y of
192− Left s -> Left $ AesonException s
195− -- FIXME this function needs more thought
197− | Just (_ :: AsyncException) <- fromException e = False
198− -- Would be nice... | Just (_ :: Timeout) <- fromException e = False
201decodeEither :: FromJSON a => ByteString -> Either String a
182decodeEither :: FromJSON a => ByteString -> Either String a
202decodeEither bs = unsafePerformIO
183decodeEither bs = unsafePerformIO