Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Data/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is misleading. decodeFileStrict (and others) throw all the errors B.readFile may throw, not only missing file. More correctly it should say "Doesn't modify exceptions thrown by Data.ByteString.readFile used to read the file". FWIW, readFile doesn't document any exception behavior either.

*Data.Aeson> decodeFileStrict "foo" :: IO (Maybe Int)
*** Exception: foo: withBinaryFile: permission denied (Permission denied)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit strong to call this "misleading", but feel free to make it more precise.

decodeFileStrict :: (FromJSON a) => FilePath -> IO (Maybe a)
decodeFileStrict = fmap decodeStrict . B.readFile

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading