From a1b47687e84f558fe3ab5edb560b242a9024060a Mon Sep 17 00:00:00 2001 From: Tony Hannan Date: Thu, 10 Mar 2011 19:37:48 -0500 Subject: [PATCH] Some additional error checking in connection command reply --- Database/MongoDB/Connection.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Database/MongoDB/Connection.hs b/Database/MongoDB/Connection.hs index fb89563..7b8fc05 100644 --- a/Database/MongoDB/Connection.hs +++ b/Database/MongoDB/Connection.hs @@ -52,7 +52,9 @@ commandReply :: String -> Reply -> Document -- ^ Extract first document from reply. Error if query error, using given string as prefix error message. commandReply title Reply{..} = if elem QueryError rResponseFlags then error $ title ++ ": " ++ at "$err" (head rDocuments) - else head rDocuments + else if null rDocuments + then error ("empty reply to: " ++ title) + else head rDocuments -- * Host @@ -219,8 +221,12 @@ newSetConnPool poolSize' repset net = assert (not . null $ seedHosts repset) $ d getMembers :: Name -> [ConnPool Host] -> IOE [Host] -- ^ Get members of replica set, master first. Query supplied connections until config found. +-- TODO: make master first -- TODO: Verify config for request replica set name and not some other replica set. ismaster config should include replica set name in result but currently does not. -getMembers _repsetName connections = hosts <$> untilSuccess (getReplicaInfo <=< getHostPipe) connections +getMembers _repsetName connections = do + info <- untilSuccess (getReplicaInfo <=< getHostPipe) connections + when (null $ hosts info) $ fail $ "no hosts in " ++ show info + return $ hosts info refreshMembers :: ANetwork -> Name -> [ConnPool Host] -> IOE [ConnPool Host] -- ^ Update current members with master at head. Reuse unchanged members. Throw IOError if can't connect to any and fetch config. Dropped connections are not closed in case they still have users; they will be closed when garbage collected. @@ -246,5 +252,5 @@ getSetPipe mos ReplicaSetConnPool{..} = modifyMVar currentMembers $ \conns -> do {- Authors: Tony Hannan - Copyright 2010 10gen Inc. + Copyright 2011 10gen Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -}