diff --git a/doc/changelog.rst b/doc/changelog.rst index df7d1ca90..6400f5c24 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -87,7 +87,7 @@ now accepts an `address` parameter. :mod:`~pymongo.errors` Changes .............................. -The exception class ``UnsupportedOption`` is deleted. +The exception classes ``UnsupportedOption`` and ``TimeoutError`` are deleted. :mod:`~gridfs` Changes ...................... diff --git a/pymongo/errors.py b/pymongo/errors.py index 6e95130fd..5a23040c4 100644 --- a/pymongo/errors.py +++ b/pymongo/errors.py @@ -126,12 +126,21 @@ class ExecutionTimeout(OperationFailure): """ -class TimeoutError(OperationFailure): - """DEPRECATED - will be removed in PyMongo 3.0. See WTimeoutError instead. +class WriteConcernError(OperationFailure): + """Base exception type for errors raised due to write concern. + + .. versionadded:: 3.0 """ -class WTimeoutError(TimeoutError): +class WriteError(OperationFailure): + """Base exception type for errors raised during write operations. + + .. versionadded:: 3.0 + """ + + +class WTimeoutError(WriteConcernError): """Raised when a database operation times out (i.e. wtimeout expires) before replication completes. @@ -142,7 +151,7 @@ class WTimeoutError(TimeoutError): """ -class DuplicateKeyError(OperationFailure): +class DuplicateKeyError(WriteError): """Raised when an insert or update fails due to a duplicate key error.""" diff --git a/pymongo/helpers.py b/pymongo/helpers.py index 3915bb66c..26ffc5ec8 100644 --- a/pymongo/helpers.py +++ b/pymongo/helpers.py @@ -24,10 +24,12 @@ from bson.py3compat import itervalues, string_type, iteritems from bson.son import SON from pymongo.errors import (CursorNotFound, DuplicateKeyError, - OperationFailure, ExecutionTimeout, - WTimeoutError, - NotMasterError) + NotMasterError, + OperationFailure, + WriteError, + WriteConcernError, + WTimeoutError) from pymongo.message import query @@ -244,13 +246,15 @@ def _check_write_command_response(results): error["index"] += offset if error.get("code") == 11000: raise DuplicateKeyError(error.get("errmsg"), 11000, error) + raise WriteError(error.get("errmsg"), error.get("code"), error) else: error = result["writeConcernError"] if "errInfo" in error and error["errInfo"].get('wtimeout'): # Make sure we raise WTimeoutError - raise WTimeoutError(error.get("errmsg"), - error.get("code"), error) - raise OperationFailure(error.get("errmsg"), error.get("code"), error) + raise WTimeoutError( + error.get("errmsg"), error.get("code"), error) + raise WriteConcernError( + error.get("errmsg"), error.get("code"), error) def _fields_list_to_dict(fields, option_name):