Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3928

Error code 0 is rewritten to 17 when checking command responses

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            andreas.braun@mongodb.com Andreas Braun
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: