[JAVA-4219] Error Code from WriteError not propagated to MongoServerException Created: 02/Jul/21  Updated: 28/Oct/23  Resolved: 07/Apr/23

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: None
Fix Version/s: 4.3.0, 3.12.13

Type: Bug Priority: Major - P3
Reporter: Christoph Strobl Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-4922 Error Code from WriteError not propag... Closed
Related
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The current driver 4.3.0-beta3 does not seem to propagate the error code from the WriteError to the MongoWriteException in case of an E11000.

With 4.2 drivers the error code matched.

try {
	MongoCollection<org.bson.Document> collection = client.getDatabase("test").getCollection("write-error-tests");
	collection.insertOne(new org.bson.Document("_id", "id-1"));
	collection.insertOne(new org.bson.Document("_id", "id-1"));
} catch (MongoServerException e) {
	System.out.println("ServerException Code: " + e.getCode());
	System.out.println("WriteError Code     : " + ((MongoWriteException)e).getError().getCode());
}



 Comments   
Comment by Githook User [ 05/Apr/23 ]

Author:

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

Message: Update test to use 4.x Junit API

JAVA-4219
Branch: 3.12.x
https://github.com/mongodb/mongo-java-driver/commit/cd2b8146373341185e4dbbc98b5b60ada61635ef

Comment by Jeffrey Yemin [ 05/Apr/23 ]

The commit cherrypicks cleanly to 3.12.x, so re-opening this to consider releasing a 3.12.x patch containing the fix, as a user reported this under JAVA-4922.

Comment by Githook User [ 05/Apr/23 ]

Author:

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

Message: Fix regression in MongoWriteException error code

Ensure that the error code from the single WriteError is propagated to the
exception error code.

JAVA-4219
Branch: 3.12.x
https://github.com/mongodb/mongo-java-driver/commit/ad6326a84d886e5d33816fe6a28d48f608e44850

Comment by Githook User [ 02/Jul/21 ]

Author:

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

Message: Fix regression in MongoWriteException error code

Ensure that the error code from the single WriteError is propagated to the
exception error code.

JAVA-4219
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/8ded1c5c2edd6d005bc856e811bb8896e8e9fbcf

Comment by Jeffrey Yemin [ 02/Jul/21 ]

Looks like the regression was introduced in the patch for JAVA-3993.  Note that JAVA-3993 has not been included in a GA release yet, so this bug shouldn't affect anyone who's not using a 4.3.0 beta release.

Generated at Thu Feb 08 09:01:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.