Skip to content

confusion exception with lazy text encoding error #14

Description

@pbv

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")

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions