Skip to content

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Mar 13, 2017

$query = new MongoDB\Driver\Query([], ['projection' => ['' => 1]]);

echo throws(function() use ($manager, $query) {
$cursor = $manager->executeQuery(NS, $query);
Copy link
Member Author

Choose a reason for hiding this comment

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

With libmongoc 1.5.4, the segfault occurs here when the cursor is checked for an error, an exception is thrown, and the cursor is destroyed. In 1.5.5, the segfault is fixed but we still throw the exception here.

I think it might make more sense to do the same BSON validation that libmongoc does during cursor initialization in our own Query constructor, so we can instead throw an InvalidArgumentException earlier. This duplicates the validation logic, but the filter and options documents should be small enough where this isn't a concern. If this sound reasonable, I'll open a new ticket to address this for 1.3.0.

Copy link
Contributor

Choose a reason for hiding this comment

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

It depends a little bit how much code it involves. I'm generally sceptical about doing these in two places. In general, I do think it's better to have an InvalidArgumentException here.

Copy link
Member Author

@jmikola jmikola Mar 13, 2017

Choose a reason for hiding this comment

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

To clarify, we are currently limited to a RuntimeException when executeQuery() is called, because _mongoc_cursor_new_with_opts() reports an error with the MONGOC_ERROR_CURSOR domain and MONGOC_ERROR_CURSOR_INVALID_CURSOR code. I wasn't sure if you were suggesting an InvalidArgumentException at this very point (i.e. executeQuery()), but that's not possible.

Throwing an InvalidArgumentException at Query construct time should require less than ten lines of code. I'll create a ticket and submit a PR soon.

Copy link
Member Author

@jmikola jmikola Mar 13, 2017

Choose a reason for hiding this comment

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

See: #558

Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

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

LGTM

$query = new MongoDB\Driver\Query([], ['projection' => ['' => 1]]);

echo throws(function() use ($manager, $query) {
$cursor = $manager->executeQuery(NS, $query);
Copy link
Contributor

Choose a reason for hiding this comment

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

It depends a little bit how much code it involves. I'm generally sceptical about doing these in two places. In general, I do think it's better to have an InvalidArgumentException here.

@jmikola jmikola merged commit 9fd5905 into mongodb:v1.2 Mar 13, 2017
jmikola added a commit that referenced this pull request Mar 13, 2017
@jmikola jmikola deleted the 1.2-phpc-920 branch March 13, 2017 19:19
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