[JAVA-2843] Exceptions should include codeName string from server response Created: 27/Apr/18  Updated: 28/Oct/23  Resolved: 30/Apr/18

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: None
Fix Version/s: 3.8.0

Type: New Feature Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-478 Errors raised by drivers should inclu... Implementing

 Description   

As of MongoDB 3.4, error responses from the server include not only the error code and message, but also a stringified representation of the error code, in the codeName field. Drivers should ensure that this code name is accessible from any errors that are returned or exceptions that are raised based on error responses from the server.

Example responses:

MongoDB Enterprise repl0:PRIMARY> db.runCommand(

{insert: "test", documents: []}

)

{ "operationTime" : Timestamp(1524837772, 1), "ok" : 0, "errmsg" : "Write batch sizes must be between 1 and 100000. Got 0 operations.", "code" : 16, "codeName" : "InvalidLength", }

MongoDB Enterprise repl0:PRIMARY> db.runCommand({insert: "test", writeConcern:

{w: 10}

, documents: [{_id: 2}]})
{
"n" : 1,
"opTime" :

{ "ts" : Timestamp(1524837850, 1), "t" : NumberLong(15) }

,
"electionId" : ObjectId("7fffffff000000000000000f"),
"writeConcernError" :

{ "code" : 100, "codeName" : "CannotSatisfyWriteConcern", "errmsg" : "Not enough data-bearing nodes" }

,
"ok" : 1,
"operationTime" : Timestamp(1524837850, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1524837850, 1),
"signature" :

{ "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) }

}
}
Note that a writeConcernError document can also contain a codeName embedded within it. No evidence that the documents within the writeErrors array field do the same.



 Comments   
Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'username': 'jyemin', 'name': 'Jeff Yemin'}

Message: JAVA-2843: Support codeName in error responses from server

The server introduced a codeName field in error responses, which is a
stringified version of the integral error code.

This commit adds a codeName property to MongoCommandException and
WriteConcernError, which is included in various exception types
including MongoWriteConcernException.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/dde851ec07143050f26a2590691bae264bfae4d0

Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'username': 'jyemin', 'name': 'Jeff Yemin'}

Message: JAVA-2843: Add regression test for createWriteConcernHelper
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b1763a8464dc22167a55d03f308affb5d0a04299

Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'username': 'jyemin', 'name': 'Jeff Yemin'}

Message: JAVA-2843: Rename method in WriteConcernHelper
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/920d31e969220cf1ab4c48815b88ba47643036d4

Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'username': 'jyemin', 'name': 'Jeff Yemin'}

Message: JAVA-2843: Replace duplicated code with use of WriteConcernHelper
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/8d9477b291f000c81daebe97de1f9c0a65cd4b3f

Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'username': 'jyemin', 'name': 'Jeff Yemin'}

Message: JAVA-2843: Move WriteConcernHelper class to internal package

Move from com.mongodb.operation to com.mongodb.internal.operation and
make it public, so that it can be shared by multiple packages
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/84be7abfa518f6d1d3ec2d5f16742e3f1c440d55

Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'username': 'jyemin', 'name': 'Jeff Yemin'}

Message: JAVA-2843: Move serverVersionIsAtLeast... methods

Move from OperationHelper to ServerVersionHelper class in internal
package to aid in a subsequent move of WriteConcernHelper to an internal
package
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b31de79f011cc3cc0962ad97eec37c3f9c95319f

Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'username': 'jyemin', 'name': 'Jeff Yemin'}

Message: JAVA-2843: Move writeConcernErrorTransformer method

Move from WriteConcernHelper to CommandOperationHelper to aid in a
subsequent move of WriteConcernHelper to an internal package
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/e09d73f9907f3e2ab63452c2419169a074505de7

Generated at Thu Feb 08 08:58:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.