Skip to content

Exceptions inside withFile incorrectly annotated `withFile`

Summary

withFile on failure includes the file name and exception even if the exception wasn't related to the file operations.

Steps to reproduce

Given the file test.hs:

import System.IO
main = withFile "test.txt" WriteMode $ \_ -> fail "test"

I see:

C:\Neil>runhaskell test.hs
test.hs: test.txt: withFile: user error (test)

Expected behavior

If I call fail, I don't expect withFile to annotate that the withFile was at fault, since it had nothing to do. I would expect the error:

user error (test)

Environment

  • GHC version used: 9.2 and above on Mac, Windows, Linux exhibit this behaviour. Older versions don't.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information