Null ErrorCode & Cause in MongoWriteException thrown at executeSingleWriteRequest

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Unknown
    • None
    • Affects Version/s: 5.0.0
    • Component/s: None
    • None
    • None
    • Java Drivers
    • Hide

      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?

      Show
      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?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      We discovered that the Java driver sometimes throws a `MongoWriteException` with null error code and cause (sample attached down below) when executing a single write request. Upon checking the driver code it seemed that this is due to when mapping a `MongoBulkWriteException` to a `MongoWriteException`, it assumes when `WriteError` exists in the bulk exception it shall have non null ErrorCode etc., but it seemed, from the actual thrown exceptions these values are populated as null (https://github.com/mongodb/mongo-java-driver/blob/5c37b88313afef00a8fb4781dd84b1a383661373/driver-sync/src/main/com/mongodb/client/internal/MongoCollectionImpl.java#L1085-L1094). This left the end exception to contain no information for clients to properly identify the cause of write failures. This ticket has been raised to fix the behaviour by tackling such null cases correctly and map all information available in the original `MongoBulkWriteException` to the thrown `MongoWriteException`.

      Sample exception:

      java.io.IOException: MongoWriteException: cause: null; error code: null; server addr: <cluster-address>
          at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1091)
          at com.mongodb.client.internal.MongoCollectionImpl.executeUpdate(MongoCollectionImpl.java:1068)
          at com.mongodb.client.internal.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:585)
          at <client-app-stacktrace>...
      

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Java driver version: 5.0.0

      Server: 6.0.15 on Atlas, sharded cluster 

      How to Reproduce

      N/A - due to lack of information from the thrown exception cause of the problem and steps to reproduce remained unclear.

      Additional Background

      N/A

            Assignee:
            Unassigned
            Reporter:
            Gordon Wang
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: