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

[#372] Warn on usages ofreadFileText and writeFileText #407

Merged
merged 1 commit into from
Apr 14, 2022

Conversation

chshersh
Copy link
Contributor

@chshersh chshersh commented Apr 14, 2022

Resolves #372

Here is an example of exceptions:

chshersh@ubuntu:~$ cat test.txt 
Привет!

chshersh@ubuntu:~$ file --mime test.txt 
test.txt: text/plain; charset=utf-8

chshersh@ubuntu:~$ LANG=en_GB.UTF-16 cabal repl -b text
Resolving dependencies...
Build profile: -w ghc-9.2.1 -O1
In order, the following will be built (use -v for more details):
 - fake-package-0 (lib) (first run)
Configuring library for fake-package-0..
Preprocessing library for fake-package-0..
Warning: No exposed modules
GHCi, version 9.2.1: https://www.haskell.org/ghc/  :? for help

ghci> readFile "test.txt" 
"*** Exception: test.txt: hGetContents: invalid argument (invalid byte sequence)
ghci> import qualified Data.Text.IO as TIO
ghci> TIO.readFile "test.txt" 
*** Exception: test.txt: hGetContents: invalid argument (invalid byte sequence)
ghci> import qualified Data.Text.Lazy.IO as LTIO
ghci> LTIO.readFile "test.txt" 
"*** Exception: test.txt: hGetContents: invalid argument (invalid byte sequence)

@chshersh chshersh requested a review from vrom911 as a code owner April 14, 2022 14:08
@chshersh chshersh self-assigned this Apr 14, 2022
@chshersh chshersh added remove enhancement New feature or request doc README, Haddock documentation, tutorials and removed remove labels Apr 14, 2022
@@ -68,6 +77,7 @@ readFileText :: MonadIO m => FilePath -> m Text
readFileText = liftIO . T.readFile
{-# SPECIALIZE readFileText :: FilePath -> IO Text #-}
{-# INLINE readFileText #-}
{-# WARNING readFileText ["'readFileText' depends on the system's locale settings and can throw unexpected exceptions.", "Use 'readFileBS' instead."] #-}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using list of strings here to display on different lines as written in docs:

Example:

image

Copy link
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

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

Awesome!

@vrom911 vrom911 merged commit 1cd9f2e into main Apr 14, 2022
@vrom911 vrom911 deleted the chshersh/372-Warn-on-usages-ofreadFileText-and branch April 14, 2022 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc README, Haddock documentation, tutorials enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn on usages ofreadFileText and writeFileText
2 participants