git.iko.soy/typeable/bloodhound
on master help sign in
Try to debug travis errors on some ES versions
8f7ca41Michael Xavier
src/Database/Bloodhound/Client.hs+4−5
@@ -324,7 +324,9 @@ existentialQuery url = do
324-- | Tries to parse a response body as the expected type @a@ and
324-- | Tries to parse a response body as the expected type @a@ and
325-- failing that tries to parse it as an EsError. All well-formed, JSON
325-- failing that tries to parse it as an EsError. All well-formed, JSON
326-- responses from elasticsearch should fall into these two
326-- 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.
328parseEsResponse :: (MonadThrow m, FromJSON a) => Reply
330parseEsResponse :: (MonadThrow m, FromJSON a) => Reply
329 -> m (Either EsError a)
331 -> m (Either EsError a)
330parseEsResponse reply
332parseEsResponse reply
@@ -333,14 +335,11 @@ parseEsResponse reply
333 Left _ -> tryParseError
335 Left _ -> tryParseError
334 | otherwise = tryParseError
336 | otherwise = tryParseError
335 where body = responseBody reply
337 where body = responseBody reply
336− stat = responseStatus reply
337− hdrs = responseHeaders reply
338− cookies = responseCookieJar reply
339 tryParseError = case eitherDecode body of
338 tryParseError = case eitherDecode body of
340 Right e -> return (Left e)
339 Right e -> return (Left e)
341 -- this case should not be possible
340 -- this case should not be possible
342 Left _ -> explode
341 Left _ -> explode
343− explode = throwM (StatusCodeException stat hdrs cookies)
342+ explode = throwM (EsProtocolException body)
344
343
345-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
344-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
346-- in IO
345-- in IO
src/Database/Bloodhound/Types.hs+11
@@ -74,6 +74,7 @@ module Database.Bloodhound.Types
74 , EsResult(..)
74 , EsResult(..)
75 , EsResultFound(..)
75 , EsResultFound(..)
76 , EsError(..)
76 , EsError(..)
77+ , EsProtocolException(..)
77 , IndexAlias(..)
78 , IndexAlias(..)
78 , IndexAliasName(..)
79 , IndexAliasName(..)
79 , IndexAliasAction(..)
80 , IndexAliasAction(..)
@@ -565,6 +566,16 @@ data EsResultFound a = EsResultFound { _version :: DocVersion
565data EsError = EsError { errorStatus :: Int
566data EsError = EsError { errorStatus :: Int
566 , errorMessage :: Text } deriving (Eq, Show, Generic, Typeable)
567 , errorMessage :: Text } deriving (Eq, Show, Generic, Typeable)
567
568
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+
568data IndexAlias = IndexAlias { srcIndex :: IndexName
579data IndexAlias = IndexAlias { srcIndex :: IndexName
569 , indexAlias :: IndexAliasName } deriving (Eq, Show, Generic, Typeable)
580 , indexAlias :: IndexAliasName } deriving (Eq, Show, Generic, Typeable)
570
581
tests/tests.hs+11−1
@@ -458,7 +458,6 @@ instance ApproxEq UpdatableIndexSetting where
458 a =~ b = a == b
458 a =~ b = a == b
459
459
460
460
461−
462noDuplicates :: Eq a => [a] -> Bool
461noDuplicates :: Eq a => [a] -> Bool
463noDuplicates xs = nub xs == xs
462noDuplicates xs = nub xs == xs
464
463
@@ -493,6 +492,7 @@ instance Arbitrary a => Arbitrary (Hit a) where
493 <*> arbitraryScore
492 <*> arbitraryScore
494 <*> arbitrary
493 <*> arbitrary
495 <*> arbitrary
494 <*> arbitrary
495+ shrink = genericShrink
496
496
497
497
498instance Arbitrary a => Arbitrary (SearchHits a) where
498instance Arbitrary a => Arbitrary (SearchHits a) where
@@ -501,6 +501,7 @@ instance Arbitrary a => Arbitrary (SearchHits a) where
501 score <- arbitraryScore
501 score <- arbitraryScore
502 hs <- arbitrary
502 hs <- arbitrary
503 return $ SearchHits tot score hs
503 return $ SearchHits tot score hs
504+ shrink = genericShrink
504
505
505reduceSize :: Gen a -> Gen a
506reduceSize :: Gen a -> Gen a
506reduceSize f = sized $ \n -> resize (n `div` 2) f
507reduceSize f = sized $ \n -> resize (n `div` 2) f
@@ -538,9 +539,13 @@ instance Arbitrary AliasRouting where
538 <$> (Just <$> arbitrary)
539 <$> (Just <$> arbitrary)
539 <*> (Just <$> arbitrary)
540 <*> (Just <$> arbitrary)
540 allAlias = AllAliasRouting <$> arbitrary
541 allAlias = AllAliasRouting <$> arbitrary
542+ shrink = genericShrink
543+
541
544
542instance Arbitrary FieldName where
545instance Arbitrary FieldName where
543 arbitrary = FieldName . T.pack <$> listOf1 arbitraryAlphaNum
546 arbitrary = FieldName . T.pack <$> listOf1 arbitraryAlphaNum
547+ shrink = genericShrink
548+
544
549
545instance Arbitrary RegexpFlags where
550instance Arbitrary RegexpFlags where
546 arbitrary = oneof [ pure AllRegexpFlags
551 arbitrary = oneof [ pure AllRegexpFlags
@@ -548,9 +553,12 @@ instance Arbitrary RegexpFlags where
548 , SomeRegexpFlags <$> genUniqueFlags
553 , SomeRegexpFlags <$> genUniqueFlags
549 ]
554 ]
550 where genUniqueFlags = NE.fromList . nub <$> listOf1 arbitrary
555 where genUniqueFlags = NE.fromList . nub <$> listOf1 arbitrary
556+ shrink = genericShrink
557+
551
558
552instance Arbitrary IndexAliasCreate where
559instance Arbitrary IndexAliasCreate where
553 arbitrary = IndexAliasCreate <$> arbitrary <*> reduceSize arbitrary
560 arbitrary = IndexAliasCreate <$> arbitrary <*> reduceSize arbitrary
561+ shrink = genericShrink
554
562
555instance Arbitrary Query where
563instance Arbitrary Query where
556 arbitrary = reduceSize $ oneof [ TermQuery <$> arbitrary <*> arbitrary
564 arbitrary = reduceSize $ oneof [ TermQuery <$> arbitrary <*> arbitrary
@@ -581,6 +589,7 @@ instance Arbitrary Query where
581 , QueryRangeQuery <$> arbitrary
589 , QueryRangeQuery <$> arbitrary
582 , QueryRegexpQuery <$> arbitrary
590 , QueryRegexpQuery <$> arbitrary
583 ]
591 ]
592+ shrink = genericShrink
584
593
585instance Arbitrary Filter where
594instance Arbitrary Filter where
586 arbitrary = reduceSize $ oneof [ AndFilter <$> arbitrary <*> arbitrary
595 arbitrary = reduceSize $ oneof [ AndFilter <$> arbitrary <*> arbitrary
@@ -601,6 +610,7 @@ instance Arbitrary Filter where
601 , RangeFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
610 , RangeFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
602 , RegexpFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
611 , RegexpFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
603 , TermFilter <$> arbitrary <*> arbitrary]
612 , TermFilter <$> arbitrary <*> arbitrary]
613+ shrink = genericShrink
604
614
605instance Arbitrary ReplicaBounds where
615instance Arbitrary ReplicaBounds where
606 arbitrary = oneof [ replicasBounded
616 arbitrary = oneof [ replicasBounded