Skip to content

Warn about possible exceptions during file decoding - #1022

Merged
Lysxia merged 1 commit into
haskell:masterfrom
deemp:master
Jul 2, 2026
Merged

Warn about possible exceptions during file decoding#1022
Lysxia merged 1 commit into
haskell:masterfrom
deemp:master

Conversation

@deemp

@deemp deemp commented May 20, 2023

Copy link
Copy Markdown
Contributor

In my project, I spent a couple of hours trying to determine the reason for an exception withBinaryFile: does not exist (No such file or directory).
After reading the current aeson docs, I expected that the case when the file is missing is also reported as a String error.

I see that currently, this is not true. I'm not sure these functions should handle missing files so I suggest to just warn about possible exceptions.

@Lysxia
Lysxia merged commit ff78f63 into haskell:master Jul 2, 2026
0 of 11 checks passed
@Lysxia

Lysxia commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Comment thread src/Data/Aeson.hs
-- 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants