Skip to content

PHPC-613, PHPC-615: Improve toJSON() error handling #249

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 3 commits into from
Mar 4, 2016

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Mar 2, 2016

@@ -1575,10 +1575,19 @@ PHP_FUNCTION(toJSON)
char *str;
size_t str_len;
str = bson_as_json(b, &str_len);

if (!str) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Could not convert BSON document to JSON");
Copy link
Contributor

Choose a reason for hiding this comment

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

"JSON string" instead of just JSON?

jmikola added 3 commits March 4, 2016 11:18
This adds additional error tests for toJSON(), which demonstrate the problem when both exceptions might have been thrown.

Additionally, this ensures that the bson_reader_t is freed before returning. Previously, the code relied on the free after the second exception was thrown.
@jmikola jmikola merged commit 9168392 into mongodb:master Mar 4, 2016
jmikola added a commit that referenced this pull request Mar 4, 2016
@jmikola jmikola deleted the phpc-613 branch March 4, 2016 16:27
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