Skip to content

Commit

Permalink
Merge pull request #122 from haskell-works/tip-toe-around-monad-fail
Browse files Browse the repository at this point in the history
Tip toe around monad fail
  • Loading branch information
AlexeyRaga authored Oct 3, 2019
2 parents f767469 + 54caaf8 commit f0b432d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ workflows:
context: haskell-ci
binary-cache-uri: ${BINARY_CACHE_URI-"http://hw-binary-cache-us-west-2-a.s3-website-us-west-2.amazonaws.com/archive"}

- haskell/build-with-binary-cache:
name: GHC 8.8.1
executor: haskell/ghc-8_8_1
context: haskell-ci
binary-cache-uri: ${BINARY_CACHE_URI-"http://hw-binary-cache-us-west-2-a.s3-website-us-west-2.amazonaws.com/archive"}

- github/release-cabal:
context: haskell-ci
name: GitHub Release
checkout: true
requires:
- GHC 8.4.4
- GHC 8.6.5
- GHC 8.8.1
filters:
branches:
only: master
Expand Down
10 changes: 5 additions & 5 deletions src/Data/Avro/Decode/Get.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import qualified Data.Text.Encoding as Text
import qualified Data.Vector as V
import Prelude as P

import Data.Avro.Codec
import Data.Avro.DecodeRaw
import Data.Avro.Schema as S
import Data.Avro.Codec
import Data.Avro.DecodeRaw
import Data.Avro.Schema as S

class GetAvro a where
getAvro :: Get a
Expand Down Expand Up @@ -119,7 +119,7 @@ instance GetAvro ContainerHeader where
getCodec :: Monad m => Maybe BL.ByteString -> m Codec
getCodec (Just "null") = pure nullCodec
getCodec (Just "deflate") = pure deflateCodec
getCodec (Just x) = fail $ "Unrecognized codec: " <> BC.unpack x
getCodec (Just x) = error $ "Unrecognized codec: " <> BC.unpack x
getCodec Nothing = pure nullCodec


Expand Down Expand Up @@ -230,6 +230,6 @@ decodeBlocks element = do
sFromIntegral :: forall a b m. (Monad m, Bounded a, Bounded b, Integral a, Integral b) => a -> m b
sFromIntegral a
| aI > fromIntegral (maxBound :: b) ||
aI < fromIntegral (minBound :: b) = fail "Integral overflow."
aI < fromIntegral (minBound :: b) = error "Integral overflow."
| otherwise = return (fromIntegral a)
where aI = fromIntegral a :: Integer
5 changes: 4 additions & 1 deletion src/Data/Avro/Schema.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -407,7 +408,7 @@ parseField record = \case
name <- o .: "name"
doc <- o .:? "doc"
ty <- parseSchemaJSON (Just record) =<< o .: "type"
let err = fail "Haskell Avro bindings does not support default for aliased or recursive types at this time."
let err = error "Haskell Avro bindings does not support default for aliased or recursive types at this time."
defM <- o .:! "default"
def <- case parseFieldDefault err ty <$> defM of
Just (Success x) -> return (Just x)
Expand Down Expand Up @@ -528,7 +529,9 @@ instance Monad Result where
return = pure
Success a >>= k = k a
Error e >>= _ = Error e
#if !MIN_VERSION_base(4,13,0)
fail = MF.fail
#endif
instance Functor Result where
fmap f (Success x) = Success (f x)
fmap _ (Error e) = Error e
Expand Down

0 comments on commit f0b432d

Please sign in to comment.