From efb6b65506bc143b9bfad085433357cc44632ffa Mon Sep 17 00:00:00 2001 From: Tony Hannan Date: Wed, 7 Sep 2011 12:03:52 -0400 Subject: [PATCH] QueryFailure error code --- Database/MongoDB/Admin.hs | 2 +- Database/MongoDB/Query.hs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Database/MongoDB/Admin.hs b/Database/MongoDB/Admin.hs index 7dfc85d..2ce42e5 100644 --- a/Database/MongoDB/Admin.hs +++ b/Database/MongoDB/Admin.hs @@ -18,7 +18,7 @@ module Database.MongoDB.Admin ( -- ** Collection collectionStats, dataSize, storageSize, totalIndexSize, totalSize, -- ** Profiling - ProfilingLevel, getProfilingLevel, MilliSec, setProfilingLevel, + ProfilingLevel(..), getProfilingLevel, MilliSec, setProfilingLevel, -- ** Database dbStats, OpNum, currentOp, killOp, -- ** Server diff --git a/Database/MongoDB/Query.hs b/Database/MongoDB/Query.hs index c7bb67b..de91f2b 100644 --- a/Database/MongoDB/Query.hs +++ b/Database/MongoDB/Query.hs @@ -72,13 +72,13 @@ access myPipe myAccessMode myDatabase (Action action) = runReaderT (runErrorT ac data Failure = ConnectionFailure IOError -- ^ TCP connection ('Pipeline') failed. May work if you try again on the same Mongo 'Connection' which will create a new Pipe. | CursorNotFoundFailure CursorId -- ^ Cursor expired because it wasn't accessed for over 10 minutes, or this cursor came from a different server that the one you are currently connected to (perhaps a fail over happen between servers in a replica set) - | QueryFailure String -- ^ Query failed for some reason as described in the string + | QueryFailure ErrorCode String -- ^ Query failed for some reason as described in the string | WriteFailure ErrorCode String -- ^ Error observed by getLastError after a write, error description is in string | DocNotFound Selection -- ^ 'fetch' found no document matching selection deriving (Show, Eq) type ErrorCode = Int --- ^ Error code from getLastError +-- ^ Error code from getLastError or query failure instance Error Failure where strMsg = error -- ^ 'fail' is treated the same as a programming 'error'. In other words, don't use it. @@ -452,8 +452,8 @@ fromReply limit Reply{..} = do -- If response flag indicates failure then throw it, otherwise do nothing checkResponseFlag flag = case flag of AwaitCapable -> return () - CursorNotFound -> throwError (CursorNotFoundFailure rCursorId) - QueryError -> throwError (QueryFailure $ at "$err" $ head rDocuments) + CursorNotFound -> throwError $ CursorNotFoundFailure rCursorId + QueryError -> throwError $ QueryFailure (at "code" $ head rDocuments) (at "$err" $ head rDocuments) fulfill :: (MonadIO m) => DelayedBatch -> Action m Batch -- ^ Demand and wait for result, raise failure if exception