[JAVA-2108] createIndex command failure on duplicate key incorrectly parses error message Created: 05/Feb/16  Updated: 16/Feb/18  Resolved: 05/Feb/16

Status: Closed
Project: Java Driver
Component/s: Command Operations
Affects Version/s: 2.13.0
Fix Version/s: 2.14.2

Type: Bug Priority: Minor - P4
Reporter: John Morales Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

When parsing out the error message of a response to creating a unique index, the message will be "errmsg" instead of "err".

Quick reproduction test case:

   @Test
    public void createIndexErrorMessage() throws Exception {
        final MongoClient client = new MongoClient();
        try {
            final DBCollection collection = client.getDB("test").getCollection("foo");
            collection.drop();
            collection.insert(new BasicDBObject("a", 1));
            collection.insert(new BasicDBObject("a", 1));
            collection.createIndex(new BasicDBObject("a", 1), new BasicDBObject("unique", true));
            fail("should throw");
        } catch (WriteConcernException e) {
            System.out.println(e.getCommandResult());
            assertNotNull("didn't find error", e.getErrorMessage());
        } finally {
            client.close();
        }
    }
    // Output:
    // { "serverUsed" : "127.0.0.1:27017" , "ok" : 0.0 , "errmsg" : "E11000 duplicate key error index: test.foo.$a_1 dup key: { : 1 }" , "code" : 11000}
    // java.lang.AssertionError: didn't find error

Note this does not appear to affect 3.x Java driver versions.



 Comments   
Comment by Githook User [ 16/Feb/18 ]

Author:

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

Message: JAVA-2108: Check for both err and errmsg fields in WriteConcernException

Necessary since one of these can come from either a getlasterror command, which puts the error in the err field, or a normal command like createIndexes, which puts the error in the errmsg field.
Branch: 2.14.x
https://github.com/mongodb/mongo-java-driver/commit/807d02f67be8751cf8b3fcbb4ed211c3180d85a4

Comment by Jeffrey Yemin [ 31/Mar/16 ]

2.14.2 has been released with a fix for this bug.

Comment by Githook User [ 05/Feb/16 ]

Author:

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

Message: JAVA-2108: Check for both err and errmsg fields in WriteConcernException

Necessary since one of these can come from either a getlasterror command, which puts the error in the err field, or a normal command like createIndexes, which puts the error in the errmsg field.
Branch: 2.14.x
https://github.com/mongodb/mongo-java-driver/commit/807d02f67be8751cf8b3fcbb4ed211c3180d85a4

Comment by Githook User [ 05/Feb/16 ]

Author:

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

Message: JAVA-2108: Check for both err and errmsg fields in WriteConcernException

Necessary since one of these can come from either a getlasterror command, which puts the error in the err field, or a normal command like createIndexes, which puts the error in the errmsg field.
Branch: 2.x
https://github.com/mongodb/mongo-java-driver/commit/355349e01e60213564afd1b24c04ea87363b25cc

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