@@ -62,10 +62,8 @@ import Data.Aeson
6262import Data.Aeson.Types (Pair, parseMaybe, parseEither, Parser)
6363import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
6464import Data.ByteString (ByteString)
65−import qualified Data.Map as Map
6665import System.IO.Unsafe (unsafePerformIO)
67−import Control.Exception (try, throwIO, fromException, AsyncException)
68−import Control.Monad.Trans.State
66+import Control.Exception
6967import qualified Data.Conduit as C
7068import qualified Data.Conduit.List as CL
7169import qualified Data.Vector as V
@@ -164,8 +162,8 @@ decode :: FromJSON a
164162 => ByteString
165163 -> Maybe a
166164decode bs = unsafePerformIO
167− $ fmap (either (const Nothing) (either (const Nothing) Just))
168− $ decodeHelper (Y.decode bs)
165+ $ fmap (either (const Nothing) id)
166+ $ decodeHelper_ (Y.decode bs)
169167
170168decodeFile :: FromJSON a
171169 => FilePath
@@ -179,24 +177,7 @@ decodeFileEither
179177 :: FromJSON a
180178 => FilePath
181179 -> IO (Either ParseException a)
182−decodeFileEither fp = do
183− x <- try $ runResourceT $ flip evalStateT Map.empty $ Y.decodeFile fp C.$$ parse
184− case x of
185− Left e
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
190− Right y ->
191− return $ case parseEither parseJSON y of
192− Left s -> Left $ AesonException s
193− Right v -> Right v
194− where
195− -- FIXME this function needs more thought
196− shouldBeCaught e
197− | Just (_ :: AsyncException) <- fromException e = False
198− -- Would be nice... | Just (_ :: Timeout) <- fromException e = False
199− | otherwise = True
180+decodeFileEither = decodeHelper_ . Y.decodeFile
200181
201182decodeEither :: FromJSON a => ByteString -> Either String a
202183decodeEither bs = unsafePerformIO