-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workaround #2491 at all call sites #2492
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please double-check this — I think it's OK (this is a straightforward synchronous exception, handled in the IO monad) but I'm not yet fluent with Haskell exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have much experience with Haskell exceptions either. Pinging @mgsloan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since he seems busy, I'll trust my (more educated) judgement, assume this is fine, and merge this. Details below but feel free to skip.
Based on https://github.com/commercialhaskell/haskelldocumentation/blob/master/content/exceptions-best-practices.md, having read some more docs (including for
MonadCatch
, which doesn't apply here), having read the papers on Haskell exceptions (including async ones, also not applying here*), I think this is fine.*We risk catching any async
IOException
, and I understand that's bad. ButIOException
shouldn't be used for asynchronous exceptions, and evensafe-exceptions
won't help there.https://www.fpcomplete.com/blog/2016/06/announce-safe-exceptions