From 6196c8728ad2b755ac19e08869687b33350ffa7c Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Wed, 15 Dec 2010 14:15:20 -0500 Subject: [PATCH] RUBY-206 handle wtimeout behavior on 1.7.3 --- lib/mongo/connection.rb | 1 + lib/mongo/db.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 02d8663..6212d50 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -387,6 +387,7 @@ module Mongo if num_received == 1 && (error = docs[0]['err'] || docs[0]['errmsg']) close if error == "not master" + error = "wtimeout" if error == "timeout" raise Mongo::OperationFailure, docs[0]['code'].to_s + ': ' + error end diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index cd19d0f..8dbaedb 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -468,8 +468,12 @@ module Mongo raise MongoArgumentError, "DB#command requires an OrderedHash when hash contains multiple keys" end - result = Cursor.new(system_command_collection, - :limit => -1, :selector => selector, :socket => sock).next_document + begin + result = Cursor.new(system_command_collection, + :limit => -1, :selector => selector, :socket => sock).next_document + rescue OperationFailure => ex + raise OperationFailure, "Database command '#{selector.keys.first}' failed: #{ex.message}" + end if result.nil? raise OperationFailure, "Database command '#{selector.keys.first}' failed: returned null."