Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for typed-process

* Format stdout and stderr in `ExitCodeException` assuming they are in
UTF-8. See [#87](https://github.com/fpco/typed-process/pull/87).
Thanks to @9999years for the legwork on this change.

## 0.2.12.0

* Add `getPid`, `exitCodeExceptionWithOutput`,
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
- bytestring
- process >=1.2
- stm
- text
- transformers
- unliftio-core

Expand Down
12 changes: 9 additions & 3 deletions src/System/Process/Typed/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import Control.Concurrent.Async (async)
import Control.Concurrent.STM (newEmptyTMVarIO, atomically, putTMVar, readTMVar, STM, tryPutTMVar, throwSTM)
import System.Exit (ExitCode)
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Lazy.Char8 as L8
import Data.String (IsString (fromString))
import Control.Monad.IO.Unlift
import qualified Data.Text.Encoding.Error as TEE
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TLE

#if MIN_VERSION_process(1, 4, 0) && !WINDOWS
import System.Posix.Types (GroupID, UserID)
Expand Down Expand Up @@ -620,11 +622,15 @@ instance Show ExitCodeException where
, show (eceProcessConfig ece) { pcEnv = Nothing }
, if L.null (eceStdout ece)
then ""
else "Standard output:\n\n" ++ L8.unpack (eceStdout ece)
else "Standard output:\n\n" ++ unpack (eceStdout ece)
, if L.null (eceStderr ece)
then ""
else "Standard error:\n\n" ++ L8.unpack (eceStderr ece)
else "Standard error:\n\n" ++ unpack (eceStderr ece)
]
where
-- Format with UTF-8, because we have to choose some encoding,
-- and UTF-8 is the least likely to be wrong in general.
unpack = TL.unpack . TLE.decodeUtf8With TEE.lenientDecode

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