Skip to content

Implement readFile in Terms of withFile for Prompt Closing of Handle - #714

Merged
Bodigrim merged 2 commits into
haskell:masterfrom
julmb:read-file
Oct 6, 2026
Merged

Bodigrim merged 2 commits into
haskell:masterfrom
julmb:read-file

Conversation

@julmb

@julmb julmb commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

This PR implements Data.Text.IO.readFile in terms of System.IO.withFile instead of System.IO.openFile. This ensures the handle is closed immediately in case of an exception, something that Data.Text.IO.hGetContents by itself does not guarantee.

There is more discussion about this in #712.

@Bodigrim
Bodigrim requested a review from Lysxia September 27, 2026 15:49
@Lysxia

Lysxia commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Can we write a regression test?

@Bodigrim Bodigrim linked an issue Oct 6, 2026 that may be closed by this pull request
@Bodigrim
Bodigrim merged commit ba2c006 into haskell:master Oct 6, 2026
24 checks passed
@julmb

julmb commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Sorry! I've been meaning to come back to this and add a regression test but got swamped with work and other things last week and this one. Thank you for completing the PR!

@Lysxia

Lysxia commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No worries!

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.

hGetContents does not close handle on exception

3 participants