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

Allow more detailed error reporting for failed URI parsing

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.7.0
    • Affects Version/s: None
    • Component/s: libmongoc
    • None

      It would be helpful for other drivers wrapping libmongoc if URI parsing could return a bson_error_t on error with some details about why parsing failed. Currently, NULL is returned and some messages may have been emitted via MONGOC_WARNING(), which can easily be ignored by the user (especially through another driver atop libmongoc).

      For example, we might find the following warning messages emitted while parsing read preferences:

      • Unsupported readPreference value [readPreference=%s]."
      • "Primary read preference mode conflicts with tags."

      These lines even include a comment: "Warn on conflict, since read preference will be validated later"; however, by that point, we've missed the chance to provide a meaningful error (for an exception in PHP's case) to the user.

      In the case of read preferences and write concerns, validation is deferred until the end of mongoc_uri_new():

      if (!mongoc_read_prefs_is_valid(uri->read_prefs)) {
         mongoc_uri_destroy(uri);
         return NULL;
      }
      

      The mongoc_read_prefs_is_valid() function (and its WC equivalent) aren't in the business of providing detailed error messages (nor should they be, IMO), but we do have an opportunity to point out errors during URI parsing or when the complex structures (i.e. read preference and write concern) are constructed.

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: