Bryan O'Sullivan avatar Bryan O'Sullivan committed a190444

A put should only result in a conflict if we get multiple bodies back.

Resolved over IRC with seancribbs and Vagabond.

Comments (0)

Files changed (2)

src/Network/Riak/Resolvable/Internal.hs

          | otherwise       = do
         (xs, vclock) <- doPut conn bucket key mvclock1 val w dw
         case xs of
-          []             -> return (val, vclock) -- not observed in the wild
-          [v] | v == val -> return (val, vclock)
-          ys             -> do debugValues "put" "conflict" ys
-                               go (i+1) (resolveMany' val ys) (Just vclock)
+          [_]   -> return (val, vclock)
+          (_:_) -> do debugValues "put" "conflict" xs
+                      go (i+1) (resolveMany' val xs) (Just vclock)
+          []    -> unexError "Network.Riak.Resolvable" "put"
+                   "received empty response from server"
   go (0::Int) val0 mvclock0
 {-# INLINE put #-}
 
     go (i+1) (ok++acc) conflicts
   mush (i,(k,_,c)) (cs,v) =
       case cs of
-        []           -> Right (i,(c,v)) -- not observed in the wild
-        [x] | x == c -> Right (i,(c,v))
-        _            -> Left (i,(k,Just v, resolveMany' c cs))
+        [_]   -> Right (i,(c,v))
+        (_:_) -> Left (i,(k,Just v, resolveMany' c cs))
+        []    -> unexError "Network.Riak.Resolvable" "put"
+                 "received empty response from server"
 {-# INLINE putMany #-}
 
 putMany_ :: (Resolvable a) =>

src/Network/Riak/Types/Internal.hs

     , RiakException(excModule, excFunction, excMessage)
     , netError
     , typeError
+    , unexError
     -- * Data types
     , Bucket
     , Key
       excModule :: String
     , excFunction :: String
     , excMessage :: String
-    } deriving (Eq, Typeable)
+    } | UnexpectedResponse {
+      excModule :: String
+    , excFunction :: String
+    , excMessage :: String
+    }deriving (Eq, Typeable)
 
 showRiakException :: RiakException -> String
 showRiakException exc@NetException{..} =
     "Riak network error " ++ formatRiakException exc
 showRiakException exc@TypeException{..} =
     "Riak type error " ++ formatRiakException exc
+showRiakException exc@UnexpectedResponse{..} =
+    "Riak server sent unexpected response " ++ formatRiakException exc
 
 formatRiakException :: RiakException -> String
 formatRiakException exc =
 typeError :: String -> String -> String -> a
 typeError modu func msg = throw (TypeException modu func msg)
 
+unexError :: String -> String -> String -> a
+unexError modu func msg = throw (UnexpectedResponse modu func msg)
+
 instance Show Connection where
     show conn = show "Connection " ++ host c ++ ":" ++ port c
         where c = connClient conn
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.