Skip to content

PHPLIB-636: ListIndexes should use CommandException for catching missing namespace and database errors #837

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
Jul 2, 2021

Conversation

tanlisu
Copy link
Contributor

@tanlisu tanlisu commented Jul 1, 2021

@tanlisu tanlisu requested a review from jmikola July 1, 2021 20:52
@@ -123,7 +123,7 @@ private function createOptions()
*
* @param Server $server
* @return IndexInfoIteratorIterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
* @throws CommandException for other driver errors (e.g. connection errors)
Copy link
Member

Choose a reason for hiding this comment

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

These two instances of @throws should not have been modified. Did you think to do this because of a phpcs warning that DriverRuntimeException was undefined? IIRC, it does attempt to check class references in doc block comments.

Remember that ServerException and its child classes are defined as originating from a server response. Something like a connection error (mentioned on this very line) can still be thrown by Server::executeReadCommand() and ListIndexes::executeCommand() will not catch it at all and allow it to propagate up the chain.

See Errors/Exceptions in ServerException::executeReadCommand() for a list of possible exceptions that the method might throw. Note that it doesn't mention ServerException directly, but that's covered by RuntimeException.


On a separate note, if these lines were actually supposed to be modified, we would also want to update the documentation for Errors/Exceptions in Collection::listIndexes(), the source of which is in docs/reference/method/MongoDBCollection-listIndexes.txt.

Copy link
Contributor Author

@tanlisu tanlisu Jul 2, 2021

Choose a reason for hiding this comment

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

Ah I got confused and changed it while I was changing the DriverRuntimeException to CommandException, but now I see I shouldn't have modified it in the @throws. Sorry, it makes sense to me now!

@@ -19,7 +19,7 @@

use EmptyIterator;
use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
Copy link
Member

Choose a reason for hiding this comment

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

Related to my comment below, I think we may actually need to leave this line in place to satisfy the reference in @throws (phpcs might complain otherwise, even though it's just in a comment). So CommandException should probably be added as a new line.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Test failures on MongoDB latest will be addressed by #834.

LGTM.

@tanlisu tanlisu merged commit bf6da6c into mongodb:master Jul 2, 2021
@tanlisu tanlisu deleted the phplib-636 branch July 2, 2021 18:46
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