From d0bbcd7c898fa338fe73d6d411fad5ef3085f1fc Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Sat, 20 May 2023 10:37:53 +0300 Subject: [PATCH] warn about exceptions during file decoding --- src/Data/Aeson.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Data/Aeson.hs b/src/Data/Aeson.hs index be321930..b7e4dcab 100644 --- a/src/Data/Aeson.hs +++ b/src/Data/Aeson.hs @@ -199,6 +199,8 @@ encodeFile fp = L.writeFile fp . encode -- -- This function parses immediately, but defers conversion. See -- 'json' for details. +-- +-- Throws an 'Exception' when the file is missing. decodeFileStrict :: (FromJSON a) => FilePath -> IO (Maybe a) decodeFileStrict = fmap decodeStrict . B.readFile @@ -226,12 +228,15 @@ decodeStrict' = decodeStrict -- If this fails due to incomplete or invalid input, 'Nothing' is -- returned. -- --- Since @2.2.0.0@ an alias for 'decodeFileStrict'. +-- Throws an 'Exception' when the file is missing. -- +-- Since @2.2.0.0@ an alias for 'decodeFileStrict'. decodeFileStrict' :: (FromJSON a) => FilePath -> IO (Maybe a) decodeFileStrict' = decodeFileStrict -- | Like 'decodeFileStrict' but returns an error message when decoding fails. +-- +-- Throws an 'Exception' when the file is missing. eitherDecodeFileStrict :: (FromJSON a) => FilePath -> IO (Either String a) eitherDecodeFileStrict = fmap eitherDecodeStrict . B.readFile @@ -253,6 +258,8 @@ eitherDecodeStrict' = eitherDecodeStrict -- | Like 'decodeFileStrict'' but returns an error message when decoding fails. -- +-- Throws an 'Exception' when the file is missing. +-- -- Since @2.2.0.0@ an alias for 'eitherDecodeFileStrict'. eitherDecodeFileStrict' :: (FromJSON a) => FilePath -> IO (Either String a) eitherDecodeFileStrict' = eitherDecodeFileStrict