Skip to content

Commit ff68f50

Browse files
committed
DOCSP-30350 reorg again and edit writing on some descriptions
1 parent 32d55d6 commit ff68f50

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

source/crud/operation-error-handling.txt

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,26 @@ The ``WriteError`` type contains the following fields:
5151
Write Exception Types
5252
---------------------
5353

54-
The driver creates write exceptions when a ``WriteError`` object is created.
54+
The driver creates write exceptions when a ``WriteError`` object is created. The
55+
driver raises a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__
56+
for any write errors that occur when performing single write operations. If an
57+
error is detected during a bulk write operation, a `MongoBulkWriteException
58+
<{+core-api+}/MongoBulkWriteException.html>`__ is thrown.
5559

56-
The write exception object contains the following fields:
57-
58-
- ``error``: the ``WriteError`` object that triggered the exception
59-
- ``serverAddress``: the address of the server where the exception occurred
60-
- ``errorLabels``: the server error labels, such as ``RetryableWriteError`` and ``TransientTransactionError``
61-
62-
Details on the different types of write exceptions and the error messages that
63-
are thrown when one is created can be found below.
60+
A ``MongoWriteException`` object contains an ``error`` field containing the
61+
``WriteError`` object that caused it. A ``MongoBulkWriteException`` contains a
62+
``writeErrors`` field containing a list of one or more ``WriteError`` objects
63+
associated with the same bulk write operation.
6464

6565
Write Exception
6666
~~~~~~~~~~~~~~~
6767

68-
The driver raises a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__ for
69-
any errors that it encounters when performing single write operations that are
70-
not related to satisfying the write concern. The ``MongoWriteException`` type
71-
contains the ``WriteError`` object.
72-
73-
For example, the driver raises a ``MongoWriteException`` if you attempt to
74-
insert a document into a collection that violates the collection's
75-
schema validation rules. Suppose the collection has a rule where the
76-
value of the ``quantity`` field must be an ``int`` type. If you
77-
attempt to insert a document where the value of ``quantity`` is
78-
``"three"``, the driver prints the following error message:
68+
For example, the driver raises a ``MongoWriteException`` if you
69+
attempt to insert a document into a collection that violates the collection's
70+
schema validation rules. Suppose the collection has a rule where the value of
71+
the ``quantity`` field must be an ``int`` type. If you attempt to insert a
72+
document where the value of ``quantity`` is ``"three"``, the driver prints the
73+
following error message:
7974

8075
.. code-block:: none
8176
:copyable: false
@@ -90,21 +85,18 @@ attempt to insert a document where the value of ``quantity`` is
9085
offendingDocument: {"name":"Apple","quantity":"three"} } } at
9186
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
9287

93-
In the preceding error message, the ``MongoWriteException`` object describes the
94-
reason for the error, and the ``Caused by`` field provides details from the
95-
``WriteError`` object about the failing operation. To address this error, you must
96-
either revise the document to adhere to the schema validation rules or bypass
97-
validation.
88+
In the preceding error message, the ``MongoWriteException`` object provides a
89+
high-level description of the error. The ``WriteError`` object provides details
90+
on the failed operation, such as the schema rules and the offending document. To
91+
address this error, you must either revise the document to adhere to the schema
92+
validation rules or bypass validation.
9893

9994
Bulk Write Exception
10095
~~~~~~~~~~~~~~~~~~~~
10196

102-
If the same example were run as a bulk write operation, a
103-
`MongoBulkWriteException <{+core-api+}/MongoBulkWriteException.html>`__ would be
104-
thrown. A ``MongoBulkWriteException`` contains a list of errors associated with
105-
the same bulk write operation if more than one item caused an error. For
106-
example, if you attempt to insert two documents that violate the collection's
107-
schema, the driver prints the following error message:
97+
Using the previous example, if you now attempt to insert two documents that
98+
violate the collection's schema, one with a ``quantity`` of ``three`` and another
99+
with a ``quantity`` of ``ten``, the driver prints the following error message:
108100

109101
.. code-block:: none
110102
:copyable: false
@@ -130,3 +122,9 @@ schema, the driver prints the following error message:
130122
at
131123
com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
132124
... 19 more
125+
126+
This exception message contains a list of the two ``WriteError`` objects. The
127+
description in the ``MongoBulkWriteException`` object is vague as
128+
documents associated with the same bulk operation could produce different error
129+
types. Refer to the individual ``WriteError`` objects' ``message`` fields to
130+
determine the cause of each error.

0 commit comments

Comments
 (0)