Skip to content

PHPC-1026: Log warnings instead of throwing for unsupported BSON types #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2017

Conversation

derickr
Copy link
Contributor

@derickr derickr commented Oct 27, 2017

No description provided.

@derickr derickr requested a review from jmikola October 27, 2017 10:27
@@ -18,45 +18,66 @@ $tests = [
pack('VCa*xVCa*xxCa*xVCa*xxx', 31, 0x03, 'e1', 9, 0x06, 'u1', 0x03, 'e2', 9, 0x06, 'u2'),
];

ini_set("mongodb.debug", "stdout");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test filename is bson-toPHP_error-006.phpt and the title still says "BSON decoding throws multiple exceptions". I think we should at least rename the title, but I don't feel strongly about the filename (technically, toPHP() is no longer erroring, just silently logging a warning).

Also, this test doesn't do much more than create an array of bytes and call toPHP(). Would it make sense to move mongodb.debug to an --INI-- block instead of using ini_set()? We don't do anything with the driver by including tools.php, so that shouldn't produce any clutter in the logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still get lots of libmongoc initialisation messages, which we don't need. So I'm keeping that.

I've changed the titles, but not the file names.

@@ -11,20 +11,29 @@ $tests = [
pack('VCa*xVa*xx', 18, 0x0E, 'foo', 4, 'bar'), // symbol
];

ini_set("mongodb.debug", "stdout");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as the test below. At least the title should be changed and the ini_set() can possibly be replaced with --INI--.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, but then there as so many other messages that we don't care about. This is better.

@@ -47,7 +47,7 @@ static bool php_phongo_bson_visit_array(const bson_iter_t *iter ARG_UNUSED, cons

static void php_phongo_bson_visit_corrupt(const bson_iter_t *iter ARG_UNUSED, void *data ARG_UNUSED) /* {{{ */
{
mongoc_log(MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, "Corrupt BSON data detected!");
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Corrupt BSON data detected!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to ask why we don't throw an exception here, but I realized that libbson already reports an error. This callback just exists as a courtesy in case the integrating library wants to do something extra.

src/bson.c Outdated
if (((php_phongo_bson_state *)data)->is_visiting_array) {
add_next_index_null(retval);
} else {
add_assoc_null(retval, key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interest of restoring 1.2's behavior, do you think it'd be better to leave the fields unset? That's less chance that the user mixes one of these up with a real BSON null type.

When we actually introduce the classes for these deprecated types, then we can start adding them to the PHP HashTable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@derickr derickr force-pushed the PHPC-1026-bson-classes branch from c3f2513 to 20bbaf3 Compare October 27, 2017 14:01
@derickr derickr merged commit 20bbaf3 into mongodb:master Oct 27, 2017
derickr added a commit that referenced this pull request Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants