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."