Skip to content

Fix base/System.IO.withFile to only annotate own exceptions #237

Closed
@ch1bo

Description

@ch1bo

Why

withFile annotating any exception raised within the wrapped action is misleading when debugging. It makes users think that something is wrong with the file opened, although another IOException was raised. This is particularly confusing if "not found" errors of other files are raised, e.g. trying to start a process which is not found on the PATH.

What

withFile should not annotate / change unrelated exceptions.

For example, given the file test.hs:

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

when run with runhaskell test.hs, produces

test.hs: test.txt: withFile: user error (test)

while it should rather exit and print:

test.hs: user error (test)

How

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedApproved by CLC votebase-4.20Implemented in base-4.20 (GHC 9.10)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions