Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to set ioe_filename in IOException #18

Merged
merged 5 commits into from
Jan 14, 2024
Merged

Make sure to set ioe_filename in IOException #18

merged 5 commits into from
Jan 14, 2024

Conversation

hasufell
Copy link
Member

No description provided.

@hasufell hasufell requested a review from Bodigrim January 13, 2024 08:30
Fixes #17

Also improves the property tests to examine more of the
IOException.
h <- openFile fp iomode
openBinaryFile osfp iomode = augmentError "openBinaryFile" osfp $ openBinaryFile' osfp iomode

openBinaryFile' :: OsPath -> IOMode -> IO Handle
Copy link
Member Author

Choose a reason for hiding this comment

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

Internal variant so that withFile doesn't accumulate two augmentError calls

hClose
action
(try . action))
Copy link
Member Author

Choose a reason for hiding this comment

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


addFilePathToIOError :: String -> OsPath -> IOException -> IOException
addFilePathToIOError fun fp ioe = unsafePerformIO $ do
fp' <- either (const (fmap OSP.toChar . OSP.unpack $ fp)) id <$> try @SomeException (OSP.decodeFS fp)
Copy link
Member Author

Choose a reason for hiding this comment

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

This matches the logic in unix: https://github.com/haskell/unix/blob/7db23ecad7593210ce38c48a462be6c50d080e00/System/Posix/PosixPath/FilePath.hsc#L161

Except we're not in IO and so I use SomeException and try to force the result as best as possible.

tests/Properties.hs Outdated Show resolved Hide resolved
Copy link
Collaborator

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

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

LGTM!

'fdToHandle' is an abomination that corrupts the IOException fields.
@hasufell hasufell merged commit b176eb5 into master Jan 14, 2024
18 checks passed
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.

2 participants