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.
- depends on
-
CDRIVER-3147 CodeNames for command errors not reported in reply of write operations
- Blocked
-
CXX-1570 Errors raised by drivers should include codeName string from server response
- Backlog
-
RUST-173 Errors raised by drivers should include codeName string from server response
- Backlog
-
CDRIVER-2635 Errors raised by drivers should include codeName string from server response
- Closed
-
CSHARP-2256 Errors raised by drivers should include codeName string from server response
- Closed
-
GODRIVER-394 Errors raised by drivers should include codeName string from server response
- Closed
-
JAVA-2843 Exceptions should include codeName string from server response
- Closed
-
MOTOR-215 Errors raised by drivers should include codeName string from server response
- Closed
-
NODE-1447 Errors raised by drivers should include codeName string from server response
- Closed
-
RUBY-1331 Errors raised by drivers should include codeName string from server response
- Closed
-
SERVER-23501 Erroring command replies should include stringified ErrorCode
- Closed
- related to
-
CDRIVER-3147 CodeNames for command errors not reported in reply of write operations
- Blocked
-
PHPC-1386 BulkWriteException and ExecutionTimeoutException do not expose codeName for server errors
- Blocked