on master help sign in
cliapp, command: Use lenient utf8 decoding
commitac47393358089bc26b3aac70bcdc5564b64a967b authorAli Abrar <aliabrar@gmail.com> dateWed 20 Feb 2019, 11:08 (8 years ago) parentfb0473a
2 files changed+6−4
lib/cliapp/src/Obelisk/CliApp/Process.hs+4−3 lib/command/src/Obelisk/Command.hs+2−1
lib/cliapp/src/Obelisk/CliApp/Process.hs+4−3
@@ -33,6 +33,7 @@ import Data.Monoid ((<>))
3333import Data.Text (Text)
3434import qualified Data.Text as T
3535import qualified Data.Text.Encoding as T
36+import Data.Text.Encoding.Error (lenientDecode)
3637import System.Exit (ExitCode (..))
3738import System.IO (Handle)
3839import System.IO.Streams (InputStream, handleToInputStream)
@@ -64,7 +65,7 @@ readProcessAndLogStderr
6465readProcessAndLogStderr sev process = do
6566 (out, _err) <- withProcess process $ \_out err -> do
6667 streamToLog =<< liftIO (streamHandle sev err)
67− liftIO $ T.decodeUtf8 <$> BS.hGetContents out
68+ liftIO $ T.decodeUtf8With lenientDecode <$> BS.hGetContents out
6869
6970readCreateProcessWithExitCode
7071 :: (MonadIO m, CliLog m, CliThrow e m, AsProcessFailure e)
@@ -89,7 +90,7 @@ readProcessAndLogOutput (sev_out, sev_err) process = do
8990
9091 -- TODO interleave stdout and stderr in log correctly
9192 streamToLog =<< liftIO (streamHandle sev_err err)
92− outText <- liftIO $ T.decodeUtf8 <$> BS.hGetContents out
93+ outText <- liftIO $ T.decodeUtf8With lenientDecode <$> BS.hGetContents out
9394 putLogRaw sev_out outText
9495
9596 liftIO (waitForProcess p) >>= \case
@@ -173,7 +174,7 @@ streamToLog
173174streamToLog stream = fix $ \loop -> do
174175 liftIO (Streams.read stream) >>= \case
175176 Nothing -> return ()
176− Just (sev, line) -> putLogRaw sev (T.decodeUtf8 line) >> loop
177+ Just (sev, line) -> putLogRaw sev (T.decodeUtf8With lenientDecode line) >> loop
177178
178179-- | Pretty print a 'CmdSpec'
179180reconstructCommand :: Process.CmdSpec -> Text
lib/command/src/Obelisk/Command.hs+2−1
@@ -17,6 +17,7 @@ import Data.List
1717import Data.Maybe (catMaybes)
1818import qualified Data.Text as T
1919import Data.Text.Encoding
20+import Data.Text.Encoding.Error (lenientDecode)
2021import GHC.StaticPtr
2122import Options.Applicative
2223import System.Directory
@@ -361,7 +362,7 @@ getArgsConfig :: IO ArgsConfig
361362getArgsConfig = pure $ ArgsConfig { _argsConfig_enableVmBuilderByDefault = System.Info.os == "darwin" }
362363
363364encodeStaticKey :: StaticKey -> String
364−encodeStaticKey = T.unpack . decodeUtf8 . Base16.encode . LBS.toStrict . Binary.encode
365+encodeStaticKey = T.unpack . decodeUtf8With lenientDecode . Base16.encode . LBS.toStrict . Binary.encode
365366
366367-- TODO: Use failWith in place of fail to be consistent.
367368decodeStaticKey :: String -> Either String StaticKey