|
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.
|