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

confusion exception with lazy text encoding error #14

Open
pbv opened this issue Oct 24, 2018 · 3 comments
Open

confusion exception with lazy text encoding error #14

pbv opened this issue Oct 24, 2018 · 3 comments

Comments

@pbv
Copy link

pbv commented Oct 24, 2018

Reading a strict text from a process that produces raw bytes fails due to an encoding error and we get a reasonable exception:

> :m System.Exit System.Process.ListLike   Data.Text
> readCreateProcessWithExitCode (shell "gzip -v < /proc/uptime") mempty :: IO (ExitCode,Text,Text)
*** Exception: fd:14: hGetContents: invalid argument (invalid byte sequence)

However, if we do the same thing with a lazy text, we get an exception relating to hClose rather than the encoding:

> :m System.Exit System.Process.ListLike   Data.Text.Lazy
> readCreateProcessWithExitCode (shell "gzip -v < /proc/uptime") mempty :: IO (ExitCode,Text,Text)
*** Exception: fd:14: hClose: invalid argument (Bad file descriptor)

In any case the reading succeeds with either strict or lazy bytestrings (because no text encoding is required):

> :m System.Exit System.Process.ListLike   Data.ByteString
> readCreateProcessWithExitCode (shell "gzip -v < /proc/uptime") mempty :: IO (ExitCode,ByteString,ByteString)
(ExitSuccess,"\US\139\b\NUL\192\132\208[\NUL\ETX3\179\&4\180\212\&37R045\183\180\208\&34\227\STX\NUL\182\150\238:\DC1\NUL\NUL\NUL","gzip: stdin: file size changed while zipping\n-11.8%\n")
> :m System.Exit System.Process.ListLike   Data.ByteString.Lazy
> readCreateProcessWithExitCode (shell "gzip -v < /proc/uptime") mempty :: IO (ExitCode,ByteString,ByteString)
(ExitSuccess,"\US\139\b\NUL\203\132\208[\NUL\ETX3\179\&46\212\&36V04\181\&01\214\179\&4\228\STX\NUL\247H\237\US\DC1\NUL\NUL\NUL","gzip: stdin: file size changed while zipping\n-11.8%\n")
@ddssff
Copy link
Member

ddssff commented Oct 25, 2018

I'm not too surprised by this, but I'm not sure how to fix it.

@ddssff
Copy link
Member

ddssff commented Oct 25, 2018

Almost any change to this code makes it strict, I don't have great intuition about this stuff.

@pbv
Copy link
Author

pbv commented Oct 25, 2018

I tried looking at the code but I haven't quite understood it yet; and, yes it is easy to introduce strictness by mistake.
I switching my code to reading lazy byteStrings and handling the encoding afterward - this avoids exception the issue.

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

No branches or pull requests

2 participants