def _check_command_response(response, reset, msg="%s", allowable_errors=[]): if not response["ok"]: if "wtimeout" in response and response["wtimeout"]: raise TimeoutError(msg % response["errmsg"]) details = response # Mongos returns the error details in a 'raw' object # for some errors. if "raw" in response: for shard in response["raw"].values(): if not shard.get("ok"): # Just grab the first error... details = shard break if not details["errmsg"] in allowable_errors: if details["errmsg"] == "not master": if reset is not None: reset() raise AutoReconnect("not master") if details["errmsg"] == "db assertion failure": ex_msg = ("db assertion failure, assertion: '%s'" % details.get("assertion", "")) if "assertionCode" in details: ex_msg += (", assertionCode: %d" % (details["assertionCode"], )) raise OperationFailure(ex_msg, details.get("assertionCode")) raise OperationFailure(msg % details["errmsg"])
def _check_command_response(response, reset, msg="%s", allowable_errors=[]): if not response["ok"]: if "wtimeout" in response and response["wtimeout"]: raise TimeoutError(msg % response["errmsg"]) if not response["errmsg"] in allowable_errors: if response["errmsg"] == "not master": reset() raise AutoReconnect("not master") if response["errmsg"] == "db assertion failure": ex_msg = ("db assertion failure, assertion: '%s'" % response.get("assertion", "")) if "assertionCode" in response: ex_msg += (", assertionCode: %d" % (response["assertionCode"], )) raise OperationFailure(ex_msg, response.get("assertionCode")) raise OperationFailure(msg % response["errmsg"])
def _check_command_response(response, reset, msg="%s", allowable_errors=[]): """Check the response to a command for errors. """ if not response["ok"]: if "wtimeout" in response and response["wtimeout"]: raise TimeoutError(msg % response["errmsg"]) details = response # Mongos returns the error details in a 'raw' object # for some errors. if "raw" in response: for shard in response["raw"].itervalues(): if not shard.get("ok"): # Just grab the first error... details = shard break errmsg = details["errmsg"] if not errmsg in allowable_errors: if (errmsg.startswith("not master") or errmsg.startswith("node is recovering")): if reset is not None: reset() raise AutoReconnect(errmsg) if errmsg == "db assertion failure": ex_msg = ("db assertion failure, assertion: '%s'" % details.get("assertion", "")) if "assertionCode" in details: ex_msg += (", assertionCode: %d" % (details["assertionCode"], )) raise OperationFailure(ex_msg, details.get("assertionCode")) code = details.get("code") # findAndModify with upsert can raise duplicate key error if code in (11000, 11001, 12582): raise DuplicateKeyError(errmsg, code) raise OperationFailure(msg % errmsg, code)