[CSHARP-2256] Errors raised by drivers should include codeName string from server response Created: 30/Apr/18  Updated: 28/Oct/23  Resolved: 16/May/18

Status: Closed
Project: C# Driver
Component/s: Error Handling
Affects Version/s: 2.6.0
Fix Version/s: 2.7.0

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Robert Stam
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 [ 16/May/18 ]

Author:

{'email': 'robert@robertstam.org', 'username': 'rstam', 'name': 'rstam'}

Message: CSHARP-2256: Errors raised by drivers should include codeName string from server response
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/42038588a295e3ca9c07b61080cc37894cf3ba6c

Generated at Wed Feb 07 21:42:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.