git.iko.soy/typeable/bloodhound
on master help sign in
Try to debug travis errors on some ES versions
commit8f7ca415823653ee6775c9b30c2973e037aea865 authorMichael Xavier <michael@michaelxavier.net> dateWed 18 Nov 2015, 15:35 (11 years ago) parent5395a0b
3 files changed+26−6
src/Database/Bloodhound/Client.hs+4−5 src/Database/Bloodhound/Types.hs+11 tests/tests.hs+11−1
src/Database/Bloodhound/Client.hs+4−5
@@ -324,7 +324,9 @@ existentialQuery url = do
324324-- | Tries to parse a response body as the expected type @a@ and
325325-- failing that tries to parse it as an EsError. All well-formed, JSON
326326-- responses from elasticsearch should fall into these two
327−-- categories. If they don't, a 'StatusCodeException' will be thrown.
327+-- categories. If they don't, a 'EsProtocolException' will be
328+-- thrown. If you encounter this, please report the full body it
329+-- reports along with your ElasticSearch verison.
328330parseEsResponse :: (MonadThrow m, FromJSON a) => Reply
329331 -> m (Either EsError a)
330332parseEsResponse reply
@@ -333,14 +335,11 @@ parseEsResponse reply
333335 Left _ -> tryParseError
334336 | otherwise = tryParseError
335337 where body = responseBody reply
336− stat = responseStatus reply
337− hdrs = responseHeaders reply
338− cookies = responseCookieJar reply
339338 tryParseError = case eitherDecode body of
340339 Right e -> return (Left e)
341340 -- this case should not be possible
342341 Left _ -> explode
343− explode = throwM (StatusCodeException stat hdrs cookies)
342+ explode = throwM (EsProtocolException body)
344343
345344-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
346345-- in IO
src/Database/Bloodhound/Types.hs+11
@@ -74,6 +74,7 @@ module Database.Bloodhound.Types
7474 , EsResult(..)
7575 , EsResultFound(..)
7676 , EsError(..)
77+ , EsProtocolException(..)
7778 , IndexAlias(..)
7879 , IndexAliasName(..)
7980 , IndexAliasAction(..)
@@ -565,6 +566,16 @@ data EsResultFound a = EsResultFound { _version :: DocVersion
565566data EsError = EsError { errorStatus :: Int
566567 , errorMessage :: Text } deriving (Eq, Show, Generic, Typeable)
567568
569+{-| 'EsProtocolException' ideally should never be thrown. It will only
570+be thrown when Bloodhound can't parse a response returned by the
571+ElasticSearch server. This should be reported as a bug to the bug
572+tracker. Be sure to include the body.
573+-}
574+data EsProtocolException = EsProtocolException { esProtoExBody :: L.ByteString }
575+ deriving (Eq, Show, Generic, Typeable)
576+
577+instance Exception EsProtocolException
578+
568579data IndexAlias = IndexAlias { srcIndex :: IndexName
569580 , indexAlias :: IndexAliasName } deriving (Eq, Show, Generic, Typeable)
570581
tests/tests.hs+11−1
@@ -458,7 +458,6 @@ instance ApproxEq UpdatableIndexSetting where
458458 a =~ b = a == b
459459
460460
461−
462461noDuplicates :: Eq a => [a] -> Bool
463462noDuplicates xs = nub xs == xs
464463
@@ -493,6 +492,7 @@ instance Arbitrary a => Arbitrary (Hit a) where
493492 <*> arbitraryScore
494493 <*> arbitrary
495494 <*> arbitrary
495+ shrink = genericShrink
496496
497497
498498instance Arbitrary a => Arbitrary (SearchHits a) where
@@ -501,6 +501,7 @@ instance Arbitrary a => Arbitrary (SearchHits a) where
501501 score <- arbitraryScore
502502 hs <- arbitrary
503503 return $ SearchHits tot score hs
504+ shrink = genericShrink
504505
505506reduceSize :: Gen a -> Gen a
506507reduceSize f = sized $ \n -> resize (n `div` 2) f
@@ -538,9 +539,13 @@ instance Arbitrary AliasRouting where
538539 <$> (Just <$> arbitrary)
539540 <*> (Just <$> arbitrary)
540541 allAlias = AllAliasRouting <$> arbitrary
542+ shrink = genericShrink
543+
541544
542545instance Arbitrary FieldName where
543546 arbitrary = FieldName . T.pack <$> listOf1 arbitraryAlphaNum
547+ shrink = genericShrink
548+
544549
545550instance Arbitrary RegexpFlags where
546551 arbitrary = oneof [ pure AllRegexpFlags
@@ -548,9 +553,12 @@ instance Arbitrary RegexpFlags where
548553 , SomeRegexpFlags <$> genUniqueFlags
549554 ]
550555 where genUniqueFlags = NE.fromList . nub <$> listOf1 arbitrary
556+ shrink = genericShrink
557+
551558
552559instance Arbitrary IndexAliasCreate where
553560 arbitrary = IndexAliasCreate <$> arbitrary <*> reduceSize arbitrary
561+ shrink = genericShrink
554562
555563instance Arbitrary Query where
556564 arbitrary = reduceSize $ oneof [ TermQuery <$> arbitrary <*> arbitrary
@@ -581,6 +589,7 @@ instance Arbitrary Query where
581589 , QueryRangeQuery <$> arbitrary
582590 , QueryRegexpQuery <$> arbitrary
583591 ]
592+ shrink = genericShrink
584593
585594instance Arbitrary Filter where
586595 arbitrary = reduceSize $ oneof [ AndFilter <$> arbitrary <*> arbitrary
@@ -601,6 +610,7 @@ instance Arbitrary Filter where
601610 , RangeFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
602611 , RegexpFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
603612 , TermFilter <$> arbitrary <*> arbitrary]
613+ shrink = genericShrink
604614
605615instance Arbitrary ReplicaBounds where
606616 arbitrary = oneof [ replicasBounded