Skip to content

Commit 7d2cd5f

Browse files
committed
Format ExitCodeException stdout and stderr with UTF-8
Closes #86
1 parent 793b2d8 commit 7d2cd5f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
- bytestring
2020
- process >=1.2
2121
- stm
22+
- text
2223
- transformers
2324
- unliftio-core
2425

src/System/Process/Typed/Internal.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import Control.Concurrent.Async (async)
2323
import Control.Concurrent.STM (newEmptyTMVarIO, atomically, putTMVar, readTMVar, STM, tryPutTMVar, throwSTM)
2424
import System.Exit (ExitCode)
2525
import qualified Data.ByteString.Lazy as L
26-
import qualified Data.ByteString.Lazy.Char8 as L8
2726
import Data.String (IsString (fromString))
2827
import Control.Monad.IO.Unlift
28+
import qualified Data.Text.Encoding.Error as TEE
29+
import qualified Data.Text.Lazy as TL
30+
import qualified Data.Text.Lazy.Encoding as TLE
2931

3032
#if MIN_VERSION_process(1, 4, 0) && !WINDOWS
3133
import System.Posix.Types (GroupID, UserID)
@@ -620,11 +622,13 @@ instance Show ExitCodeException where
620622
, show (eceProcessConfig ece) { pcEnv = Nothing }
621623
, if L.null (eceStdout ece)
622624
then ""
623-
else "Standard output:\n\n" ++ L8.unpack (eceStdout ece)
625+
else "Standard output:\n\n" ++ unpack (eceStdout ece)
624626
, if L.null (eceStderr ece)
625627
then ""
626-
else "Standard error:\n\n" ++ L8.unpack (eceStderr ece)
628+
else "Standard error:\n\n" ++ unpack (eceStderr ece)
627629
]
630+
where
631+
unpack = TL.unpack . TLE.decodeUtf8With TEE.lenientDecode
628632

629633
-- | Wrapper for when an exception is thrown when reading from a child
630634
-- process, used by 'byteStringOutput'.

0 commit comments

Comments
 (0)