-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2492 from commercialhaskell/2491-workaround-yaml-…
…intl-bug Workaround #2491 at all call sites
- Loading branch information
Showing
6 changed files
with
32 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
-- | Wrappers for Yaml functions to workaround | ||
-- https://github.com/commercialhaskell/stack/issues/2491. | ||
-- Import Data.Yaml.Extra in place of Data.Yaml to use this workaround. | ||
-- Beware these functions construct/deconstruct the entire file at once! | ||
module Data.Yaml.Extra (decodeFileEither, encodeFile, module Data.Yaml) where | ||
|
||
import Control.Exception | ||
import Data.Yaml hiding (decodeFileEither, encodeFile) | ||
import qualified Data.ByteString as B | ||
import System.IO | ||
|
||
-- Note: we refrain from using 'B.readFile' and 'B.writeFile', as they open | ||
-- the file in binary mode rather than text mode. | ||
decodeFileEither :: FromJSON a => FilePath -> IO (Either ParseException a) | ||
decodeFileEither path = | ||
handle (\(e :: IOException) -> return . Left . OtherParseException . SomeException $ e) $ | ||
withFile path ReadMode $ | ||
\hnd -> do | ||
fileContent <- B.hGetContents hnd | ||
return $ decodeEither' fileContent | ||
|
||
encodeFile :: ToJSON a => FilePath -> a -> IO () | ||
encodeFile path v = withFile path WriteMode $ | ||
\hnd -> do | ||
let fileContent = encode v | ||
B.hPut hnd fileContent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters