Skip to content

PHPC-554: Rephrase unsupported/corrupt BSON messages #306

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 1 commit into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ void php_phongo_bson_visit_corrupt(const bson_iter_t *iter ARG_UNUSED, void *dat
{
mongoc_log(MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, "Corrupt BSON data detected!");
}
/* }}} */

void php_phongo_bson_visit_unsupported_type(const bson_iter_t *iter ARG_UNUSED, const char *key, uint32_t v_type_code, void *data ARG_UNUSED) /* {{{ */
{
TSRMLS_FETCH();
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Detected unknown BSON type 0x%02hhx for fieldname \"%s\". Are you using the latest driver?", v_type_code, key);
}

bool php_phongo_bson_visit_double(const bson_iter_t *iter ARG_UNUSED, const char *key, double v_double, void *data) /* {{{ */
{
#if PHP_VERSION_ID >= 70000
Expand Down Expand Up @@ -574,7 +580,7 @@ static const bson_visitor_t php_bson_visitors = {
php_phongo_bson_visit_int64,
php_phongo_bson_visit_maxkey,
php_phongo_bson_visit_minkey,
NULL /*php_phongo_bson_visit_unsupported_type*/,
php_phongo_bson_visit_unsupported_type,
NULL /*php_phongo_bson_visit_decimal128*/,
{ NULL }
};
Expand Down Expand Up @@ -1401,8 +1407,12 @@ PHONGO_API int phongo_bson_to_zval_ex(const unsigned char *data, int data_len, p
if (bson_iter_visit_all(&iter, &php_bson_visitors, state) || iter.err_off) {
/* Iteration stopped prematurely due to corruption or a failed visitor.
* While we free the reader, state->zchild should be left as-is, since
* the calling code may want to zval_ptr_dtor() it. */
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Could not convert BSON document to a PHP variable");
* the calling code may want to zval_ptr_dtor() it. If an exception has
* been thrown already (due to an unsupported BSON type for example,
* don't overwrite with a generic exception message. */
if (!EG(exception)) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Detected corrupt BSON data");
}
bson_reader_destroy(reader);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libbson
Submodule libbson updated 1 files
+2 −2 doc/bson_value_t.page
10 changes: 5 additions & 5 deletions tests/bson/bson-toPHP_error-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ foreach ($tests as $bson) {
<?php exit(0); ?>
--EXPECTF--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
Could not convert BSON document to a PHP variable
Detected corrupt BSON data.
Copy link
Member

Choose a reason for hiding this comment

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

I believe you forgot to remove the trailing period in these expected exception messages. Fixed in e6deaeb.

OK: Got MongoDB\Driver\Exception\UnexpectedValueException
Could not convert BSON document to a PHP variable
Detected corrupt BSON data.
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
Could not convert BSON document to a PHP variable
Detected corrupt BSON data.
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
Could not convert BSON document to a PHP variable
Detected corrupt BSON data.
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
Could not convert BSON document to a PHP variable
Detected unknown BSON type 0x65 for fieldname "". Are you using the latest driver?
===DONE===
2 changes: 1 addition & 1 deletion tests/bson/bug0531.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ echo throws(function() use ($bson) {
<?php exit(0); ?>
--EXPECTF--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
Could not convert BSON document to a PHP variable
Detected unknown BSON type 0x31 for fieldname "hello". Are you using the latest driver?
===DONE===