-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
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.
- is depended on by
-
PHPC-942 Use mongoc_uri_new_with_error() to improve URI error reporting
- Closed
- is related to
-
CDRIVER-587 URI parsing logs warning on w < -1 but otherwise ignores it
- Closed
- related to
-
PHPC-1020 URI option readPreference as integer constant value
- Closed
-
PHPC-887 Throw exceptions for unexpected types in URI options array
- Closed
-
CDRIVER-2234 _mongoc_uri_build_write_concern() should report unsupported "w" option as error
- Closed