Skip to content

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

Merged
vrom911 merged 1 commit intomainfrom
chshersh/372-Warn-on-usages-ofreadFileText-and
Apr 14, 2022
Merged

[#372] Warn on usages ofreadFileText and writeFileText#407
vrom911 merged 1 commit intomainfrom
chshersh/372-Warn-on-usages-ofreadFileText-and

Conversation

@chshersh
Copy link
Copy Markdown
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
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
Copy Markdown
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
Copy Markdown
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
@ulidtko ulidtko mentioned this pull request Aug 29, 2024
8 tasks
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