[CSHARP-155] Support for error codes in command results and exceptions Created: 24/Jan/11  Updated: 03/Sep/14  Resolved: 03/Sep/14

Status: Closed
Project: C# Driver
Component/s: Feature Request
Affects Version/s: 1.0
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Aristarkh Zagorodnikov Assignee: Unassigned
Resolution: Done Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-153 Wrapping internal communication excep... Closed
is related to CSHARP-474 Review all exceptions thrown by the C... Closed

 Description   

I would like to suggest adding support for error codes in command results and (probably) exceptions, so handling specific type of errors is easier.
Comparing error messages to a predefined string seems weak to me. While current driver has only one such spot (the 'commandResult.ErrorMessage == "not master"' check in MongoDatabase.cs, I don't know if this is the only and proper message to close connection for), not having access to error code makes writing robust client-side code harder.



 Comments   
Comment by Craig Wilson [ 03/Sep/14 ]

In .NET, we should really be using exceptions to handle this. We will be reviewing all the exceptions we are throwing and attempting to better use those to help users out. Unfortunately, we are subject to the error codes the server provides and as they get better and more consistent, you will see a direct benefit in the driver.

Comment by Steve Francia [ 12/Mar/12 ]

We are going to postpone doing this until we can build support for all drivers using the same numeric codes. It's a good idea, but one we need to approach with a thoughtful universal solution.

Comment by Aristarkh Zagorodnikov [ 10/Aug/11 ]

I would like to inform that we implemented this as a set of helper methods, so if it's not going to be added, we don't need it that much (although since https://jira.mongodb.org/browse/CSHARP-299 is implemented, a common "ErrorCode" property still might be useful), so if it's not an feature that is interesting for other users, I think it should be closed.

Comment by Andrew Armstrong [ 09/Mar/11 ]

This may be better suited as a request also to the core server; some errors (like 'not master') don't actually send back a hard coded error number (so the driver internally would not be immune to servers changing the error message either), but I agree its nice to have.

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