[CDRIVER-644] bson_error_t's "code" is often wrong Created: 12/May/15  Updated: 08/Jan/24  Resolved: 04/Apr/16

Status: Closed
Project: C Driver
Component/s: errors
Affects Version/s: None
Fix Version/s: 1.4.0

Type: Bug Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CDRIVER-709 Define mongoc_error_code_t value for ... Closed
Related
related to CDRIVER-662 Inconsistent errs from CRUD functions Closed
related to CXX-808 Missing error codes for server-side e... Closed
related to PHPC-292 Running a command against a server th... Closed
related to CDRIVER-728 Error code for connection timeouts Closed
related to CDRIVER-1172 Change default error API version to 2 Backlog
related to CDRIVER-449 Could not find useful documentation o... Closed
related to CDRIVER-1434 Show set_error_api in examples Closed
is related to CXX-834 Return local mongoc errors and server... Backlog
Backwards Compatibility: Major Change

 Description   

The mongoc_error_code_t enum does not agree with the server's error codes. For example, recent servers return error code 13 if a command is unauthorized, but 13 means MONGOC_ERROR_CLIENT_IN_EXHAUST in the enum. MONGOC_ERROR_CLIENT_AUTHENTICATE, on the other hand, is 11 in the enum. Nevertheless, when a command fails on the server the driver sets the bson_error_t's code to the server error code, as if the enum values and the server's values were related. Applications comparing a bson_error_t's "code" field to the enum values are often misinformed about the cause of the error.

The enum and bson_error_t can't work as designed – the client and server can't share that list of codes, because they don't agree now and can't be made to agree in the future. I need to investigate if there is a simple upgrade path, or if I just need to document the problem now and wait for version 2.0 for a true fix.



 Comments   
Comment by Githook User [ 02/Sep/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-644 prevent setting Error API version twice
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/404f4ef537b4e553f0d905172358fdc27353e18e

Comment by Githook User [ 04/Apr/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-644 no file mongoc-error.c
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/3f078e42f6fedbcc4f6efe33df99bc7e348b9d0c

Comment by Githook User [ 04/Apr/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-644 new error API
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/d45c768682634ab7779bbde9695fef925fa49383

Comment by A. Jesse Jiryu Davis [ 29/Jan/16 ]

Current server error codes are here:

https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.err

There might be a handful, like duplicate key error, for which applications commonly have specialized error-handling logic. Those are well-known error codes have been stable in the server for many years, so we can make client-side error codes for those in the MONGOC_ERROR_SERVER domain.

We have to come up with a list of those codes, and maybe agree on a drivers spec for the list.

Comment by A. Jesse Jiryu Davis [ 28/Jan/16 ]

The root problem is that errors with QUERY or COMMAND domains, perhaps other domains as well, include error codes that might be client error codes or server error codes. There's no way to know for sure, but the meanings of the two sets of codes are different, so there isn't a clear way to diagnose an error based on its code.

We'll go with a solution proposed by mira.carey@mongodb.com. Two new functions:

void mongoc_client_pool_set_error_api (mongoc_client_pool_t *, int32_t version);
void mongoc_client_set_error_api (mongoc_client_t *, int32_t version);

The default error API version is 1, the current broken behavior.

Set the version to 2 and all server errors are now reported in a new domain, MONGOC_ERROR_SERVER. These errors have no meaning in the driver, they are simply the number returned by the server.

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