Skip to content
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

Tip toe around monad fail #122

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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