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

Forcefully set ioe_filename in IOException? #17

Closed
Bodigrim opened this issue Jan 12, 2024 · 2 comments
Closed

Forcefully set ioe_filename in IOException? #17

Bodigrim opened this issue Jan 12, 2024 · 2 comments

Comments

@Bodigrim
Copy link
Collaborator

I noticed in https://github.com/hasufell/file-io/actions/runs/7500925884/job/20420565223#step:5:295 that the exceptions seemingly do not set ioe_filename field of IOException. That's explainable: mkFD(which is responsible for this particular error) does not have a filename at hand.

A simple (crossplatform!) reproducer is this:

$ cabal repl -b file-io
ghci> :set -XQuasiQuotes
ghci> x = System.File.OsPath.openFile [System.OsPath.osp|foo|] WriteMode
ghci> y = System.File.OsPath.openFile [System.OsPath.osp|foo|] WriteMode
ghci> x
{handle: <file descriptor: 14>}
ghci> y
*** Exception: openFile: resource busy (file is locked)

It would be painful to debug such write lock in a real-life application, because the error message does not mention which filename is locked.

Could functions in file-io catch and re-throw IOExceptions, forcefully setting ioe_filename if empty?

@Bodigrim
Copy link
Collaborator Author

Essentially I'm asking to do what base does in such cases:

openFile :: FilePath -> IOMode -> IO Handle
openFile fp im = 
  catchException
    (openFile' fp im dEFAULT_OPEN_IN_BINARY_MODE True)
    (\e -> ioError (addFilePathToIOError "openFile" fp e))

It catches the underlying IO exception and rethrows it, forcefully setting ioe_filename via addFilePathToIOError.

@hasufell
Copy link
Member

Yes, we should try to mimick base as much as possible.

hasufell added a commit that referenced this issue Jan 13, 2024
Fixes #17

Also improves the property tests to examine more of the
IOException.
hasufell added a commit that referenced this issue Jan 13, 2024
Fixes #17

Also improves the property tests to examine more of the
IOException.
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

No branches or pull requests

2 participants