[CDRIVER-782] Allow more detailed error reporting for failed URI parsing Created: 06/Aug/15  Updated: 02/Nov/17  Resolved: 16/Mar/17

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.7.0

Type: Improvement Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PHPC-942 Use mongoc_uri_new_with_error() to im... Closed
Related
related to PHPC-1020 URI option readPreference as integer ... Closed
related to PHPC-887 Throw exceptions for unexpected types... Closed
related to CDRIVER-2234 _mongoc_uri_build_write_concern() sho... Closed
is related to CDRIVER-587 URI parsing logs warning on w < -1 bu... Closed
Epic Link: C Driver Connection String Spec

 Description   

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.



 Comments   
Comment by Githook User [ 21/Mar/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-782 leak in URI error test
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/25273b3c827868c47ee9072cfa6d24aed33a82bb

Comment by Githook User [ 16/Mar/17 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}

Message: CDRIVER-782 Allow more detailed error reporting for failed URI parsing
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/ba74b9fcb92d592777ccc34e04d4e50a42a630bd

Comment by Githook User [ 13/Aug/15 ]

Author:

{u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}

Message: Split out Manager constructor error tests

The extra arguments test can be skipped for HHVM (as was done in #74).

The read preference and write concern tests attempt to cover all permutations of invalid arguments. Detailed exceptions are only possible where we apply array options to the structures, since libmongoc currently provides no detailed errors when URI parsing fails (see: CDRIVER-782).
Branch: master
https://github.com/10gen-labs/mongo-php-driver-prototype/commit/960c51ace75b6d03af5b3f5002a354b0085a1efb

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