Skip to content

Commit 32d55d6

Browse files
committed
DOCSP-30350 Write exceptions, reorg
1 parent 11785f5 commit 32d55d6

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

source/crud/operation-error-handling.txt

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ appropriate actions to either handle them or correct the error-causing code.
3535
discussions, or general technical support
3636

3737
Write Error
38-
~~~~~~~~~~~
38+
-----------
3939

4040
If the driver encounters an error while performing a write operation, it
4141
creates an error of the `WriteError <{+core-api+}/WriteError.html>`__ type.
@@ -48,8 +48,22 @@ The ``WriteError`` type contains the following fields:
4848

4949
.. _java_error_write_exceptions:
5050

51+
Write Exception Types
52+
---------------------
53+
54+
The driver creates write exceptions when a ``WriteError`` object is created.
55+
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.
64+
5165
Write Exception
52-
---------------
66+
~~~~~~~~~~~~~~~
5367

5468
The driver raises a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__ for
5569
any errors that it encounters when performing single write operations that are
@@ -83,14 +97,14 @@ either revise the document to adhere to the schema validation rules or bypass
8397
validation.
8498

8599
Bulk Write Exception
86-
--------------------
100+
~~~~~~~~~~~~~~~~~~~~
87101

88102
If the same example were run as a bulk write operation, a
89103
`MongoBulkWriteException <{+core-api+}/MongoBulkWriteException.html>`__ would be
90-
thrown. A ``MongoBulkWriteException`` can contain a list of errors associated
91-
with the same bulk write operation. For example, if you attempt to insert two
92-
documents that violate the collection's schema, the error message would appear
93-
as follows:
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:
94108

95109
.. code-block:: none
96110
:copyable: false
@@ -106,9 +120,9 @@ as follows:
106120
schemaRules: { bsonType: "int", description: "must be an integer" },
107121
offendingDocument: {"name":"Apple","quantity":"three"} }} at
108122
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
109-
at
110-
com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
111-
... 19 more Caused by: com.mongodb.MongoWriteException: WriteError{code=121,
123+
at com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
124+
... 19 more
125+
Caused by: com.mongodb.MongoWriteException: WriteError{code=121,
112126
message='Document failed validation', details={ operator: "$jsonSchema",
113127
schemaRules: { bsonType: "int", description: "must be an integer" },
114128
offendingDocument: {"name":"Banana","quantity":"ten"} }} at

0 commit comments

Comments
 (0)