-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-1689 Make the Atlas Search exception more specific #1794
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
base: v2.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a more specific exception (SearchNotSupportedException) to handle Atlas Search-related errors that occur during aggregation operations. The change improves error handling by catching generic server exceptions and re-throwing them as a more specific exception type when they relate to unsupported search functionality.
- Created a new
SearchNotSupportedExceptionclass to identify and handle search-related server errors - Modified the
Aggregateoperation to catch and re-throw search-specific exceptions during command execution
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Exception/SearchNotSupportedException.php | New exception class that extends ServerException and provides logic to identify search-related errors based on error codes |
| src/Operation/Aggregate.php | Added try-catch block to intercept ServerException and re-throw as SearchNotSupportedException when appropriate |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f9c8674 to
604ef77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## v2.x #1794 +/- ##
============================================
- Coverage 87.74% 87.63% -0.11%
- Complexity 3185 3196 +11
============================================
Files 424 425 +1
Lines 6289 6332 +43
============================================
+ Hits 5518 5549 +31
- Misses 771 783 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
9d13244 to
17b1c47
Compare
14c3251 to
50fbc84
Compare
|
Since mongo 6.0.11-ent, the |
jmikola
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GromNaN: Was there anything in this PR you wanted to keep, or should it all be abandoned (given the difficulty in error detection)?
088f9ae to
53e56ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I found a more reliable way to detect when Search indexes are supported. Also fixed the exception for update and drop search index. |
…old server versions
…o Atlas, thanks to Community Search
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
9c70230 to
80a2c92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // MongoDB 7-ent: Search index commands are only supported with Atlas. | ||
| 115 => true, | ||
| // MongoDB 4 to 6, 7-community | ||
| 59 => match ($exception->getMessage()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match inception 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A decision tree 🎄
| default => false, | ||
| }, | ||
| // MongoDB 4 to 6 | ||
| 40324 => match ($exception->getMessage()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you trawl through all the old versions' source code to find all these error codes? 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried many server versions using mongo-orchestration, m and mongo-launch; Atlas M0 and Atlas Local Docker.
Then our test matrix helped validate all the versions.
| try { | ||
| $cursor = $this->executeCommand($server, $command); | ||
| } catch (ServerException $exception) { | ||
| if (SearchNotSupportedException::isSearchNotSupportedError($exception)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution
|
|
||
| try { | ||
| $collection->listSearchIndexes(); | ||
| } catch (SearchNotSupportedException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically are you doing it like these because it's too complex to skip if it is supported? Can't we just do the inverse of the check you do in skipIfSearchIndexIsNotSupported and expect an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a way to test even if skipIfSearchIndexIsNotSupported is incomplete. Here, I test each operation one by one to ensure that if there is an exception, it is properly wrapped.
I noticed that not all server versions are consistent. As an example in mongo 6.0.11-ent, the $listSearchIndexes stage returns an empty list but createSearchIndexes returns an error.
Fix PHPLIB-1689
Conditions imported from https://github.com/mongodb/laravel-mongodb/blob/a2b4ab86dfc9248050b2592d9830773ac335774e/src/Schema/Builder.php#L386-L395