git.iko.soy/typeable/bloodhound
on master help sign in
Made EsProtocolException more helpful
c18318dChris Allen
src/Bloodhound/Import.hs+3
@@ -79,3 +79,6 @@ deleteSeveral ks hm = foldr HM.delete hm ks
79oPath :: ToJSON a => NonEmpty Text -> a -> Value
79oPath :: ToJSON a => NonEmpty Text -> a -> Value
80oPath (k :| []) v = object [k .= v]
80oPath (k :| []) v = object [k .= v]
81oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
81oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
82+
83+tshow :: Show a => a -> Text
84+tshow = T.pack . show
src/Database/V5/Bloodhound/Client.hs+20−16
@@ -639,19 +639,24 @@ existentialQuery url = do
639-- categories. If they don't, a 'EsProtocolException' will be
639-- categories. If they don't, a 'EsProtocolException' will be
640-- thrown. If you encounter this, please report the full body it
640-- thrown. If you encounter this, please report the full body it
641-- reports along with your Elasticsearch verison.
641-- reports along with your Elasticsearch verison.
642−parseEsResponse :: (MonadThrow m, FromJSON a) => Reply
642+parseEsResponse :: ( MonadThrow m
643+ , FromJSON a
644+ )
645+ => Reply
643 -> m (Either EsError a)
646 -> m (Either EsError a)
644parseEsResponse reply
647parseEsResponse reply
645 | respIsTwoHunna reply = case eitherDecode body of
648 | respIsTwoHunna reply = case eitherDecode body of
646 Right a -> return (Right a)
649 Right a -> return (Right a)
650+ Left err ->
647− Left _ -> tryParseError
651+ tryParseError err
648− | otherwise = tryParseError
652+ | otherwise = tryParseError "Non-200 status code"
649 where body = responseBody reply
653 where body = responseBody reply
654+ tryParseError originalError
650− tryParseError = case eitherDecode body of
655+ = case eitherDecode body of
651− Right e -> return (Left e)
656+ Right e -> return (Left e)
652− -- this case should not be possible
657+ -- Failed to parse the error message.
653− Left _ -> explode
658+ Left err -> explode ("Original error was: " <> originalError <> " Error parse failure was: " <> err)
654− explode = throwM (EsProtocolException body)
659+ explode errorMsg = throwM (EsProtocolException (T.pack errorMsg) body)
655
660
656-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
661-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
657-- in IO
662-- in IO
@@ -711,16 +716,15 @@ listIndices =
711 parse . responseBody =<< get =<< url
716 parse . responseBody =<< get =<< url
712 where
717 where
713 url = joinPath ["_cat/indices?format=json"]
718 url = joinPath ["_cat/indices?format=json"]
714− parse body = maybe (throwM (EsProtocolException body)) return $ do
719+ parse body = either (\msg -> (throwM (EsProtocolException (T.pack msg) body))) return $ do
715− vals <- decode body
720+ vals <- eitherDecode body
716 forM vals $ \val ->
721 forM vals $ \val ->
717 case val of
722 case val of
718− Object obj -> do
723+ Object obj ->
719− indexVal <- HM.lookup "index" obj
724+ case HM.lookup "index" obj of
720− case indexVal of
721− String txt -> Just (IndexName txt)
725+ (Just (String txt)) -> Right (IndexName txt)
722− _ -> Nothing
726+ v -> Left $ "indexVal in listIndices failed on non-string, was: " <> show v
723− _ -> Nothing
727+ v -> Left $ "One of the values parsed in listIndices wasn't an object, it was: " <> show v
724
728
725-- | 'updateIndexAliases' updates the server's index alias
729-- | 'updateIndexAliases' updates the server's index alias
726-- table. Operations are atomic. Explained in further detail at
730-- table. Operations are atomic. Explained in further detail at
src/Database/V5/Bloodhound/Internal/Client.hs+3−2
@@ -693,8 +693,9 @@ sure that your mappings are correct, then this error may be an indication of an
693incompatibility between Bloodhound and Elasticsearch. Please open a bug report
693incompatibility between Bloodhound and Elasticsearch. Please open a bug report
694and be sure to include the exception body.
694and be sure to include the exception body.
695-}
695-}
696−newtype EsProtocolException = EsProtocolException
696+data EsProtocolException = EsProtocolException
697+ { esProtoExMessage :: !Text
697− { esProtoExBody :: LByteString
698+ , esProtoExBody :: !LByteString
698 } deriving (Eq, Show)
699 } deriving (Eq, Show)
699
700
700instance Exception EsProtocolException
701instance Exception EsProtocolException