Skip to content

Commit

Permalink
Fix encoding error for Windows 10 non UTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
gibranrosa committed Mar 19, 2020
1 parent 81f8ce3 commit b446506
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Spago/Purs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ module Spago.Purs
import Spago.Prelude

import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text.Encoding
import Data.Text.Encoding.Error (lenientDecode)
import qualified Data.Versions as Version
import qualified Spago.Dhall as Dhall

import qualified Spago.Messages as Messages

import qualified Turtle.Bytes

newtype ModuleName = ModuleName { unModuleName :: Text }
newtype TargetPath = TargetPath { unTargetPath :: Text }
Expand Down Expand Up @@ -125,13 +127,13 @@ version = versionImpl "purs"
psaVersion = versionImpl "psa"

versionImpl :: Text -> Spago (Either Text Version.SemVer)
versionImpl purs = shellStrictWithErr (purs <> " --version") empty >>= \case
versionImpl purs = Turtle.Bytes.shellStrictWithErr (purs <> " --version") empty >>= \case
(ExitSuccess, out, _err) -> do
let versionText = headMay $ Text.split (== ' ') out
let versionText = headMay $ Text.split (== ' ') (Text.Encoding.decodeUtf8With lenientDecode out)
parsed = versionText >>= (hush . Version.semver)

pure $ case parsed of
Nothing -> Left $ Messages.failedToParseCommandOutput (purs <> " --version") out
Nothing -> Left $ Messages.failedToParseCommandOutput (purs <> " --version") (Text.Encoding.decodeUtf8With lenientDecode out)
Just p -> Right p
(_, _out, _err) -> pure $ Left $ "Failed to run '" <> purs <> " --version'"

Expand Down

0 comments on commit b446506

Please sign in to comment.