[CDRIVER-3928] Error code 0 is rewritten to 17 when checking command responses Created: 11/Mar/21  Updated: 10/Feb/23

Status: Backlog
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Andreas Braun Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CDRIVER-4576

 Description   

CDRIVER-3885 requires drivers making a distinction between command error responses returning an error code and those not providing one. While implementing this, I noticed that error code 0 is automatically changed to MONGO_ERR_QUERY_FAILURE (17). Quoting from the pull request (link to comment):

_mongoc_cmd_check_ok and _mongoc_cmd_check_ok_no_wce rely on _parse_error_reply to extract message and code information from a bson_t reply. If no code is found in the reply document, a code of 0 is returned.

The two check methods then take this information and build a bson_error_t of it, but only after changing the error code to MONGOC_ERROR_QUERY_FAILURE (17) if it was 0, essentially defaulting to that error code. _mongoc_cmd_check_ok_no_wce and _mongoc_cmd_check_ok should not change the error code, but instead this logic should be moved to wherever the MONGOC_ERROR_QUERY_FAILURE is needed.

clyde.bazile pointed out that other code may assume an error code 0 to mean that everything was successful, so this will have to be covered. A viable strategy may be to expand bson_error_t to expose if an error code was given. The code field in that struct is declared as uint32_t, so we can't use -1 to show that no code was provided. Adding a has_code field to bson_error_t would work, but this may cause unwanted side effects in public APIs to cover this.


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