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
Handle Elastica Transport errors #1465
Handle Elastica Transport errors #1465
Conversation
Updated the repo to not point at my personal fork, tests should pass now |
Hmm almost cleaned that up – any idea how to make php-5.6 tests to pass? do i have to back-port into the 5.x branch? |
composer.json
Outdated
@@ -19,7 +19,7 @@ | |||
"symfony/property-access": "^3.2|^4", | |||
"pagerfanta/pagerfanta": "^1.0.5|^2.0", | |||
"psr/log": "^1.0", | |||
"ruflin/elastica": "^5.2.1|^6.0" | |||
"ruflin/elastica": "dev-master" |
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.
We would like to keep stable packages.
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.
Completely agreed, alas last release from ruflin/elastica is from waaay back
Release 6.0.2 @ruflin ruflin released this on May 29 · 8 commits to master since this release
See link for reference https://github.com/ruflin/Elastica/releases
And the commit that's needed for this PR, is a fairly recent one on master
I'm not sure what's the best way around this? ask ruflin to release a new version?
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.
@jandom Is a new release needed from master?
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.
@ruflin nothing would make me more happy – but i'm not sure what your release cycle is like/don't want to bother if you're waiting for something else to merge in
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.
@ruflin yeah let's have a new ruflin/Elastica release, if that's okay – it'll push this PR forward
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.
Next week is totally appropriate
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.
@ruflin super-gentle nudge if there are any updates on the new release of ruflin/Elastica?
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.
Thanks for the nudge ;-) Just opened the PR to prepare the release. Now I only need a review for it: ruflin/Elastica#1547
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.
@jandom This should help: https://github.com/ruflin/Elastica/releases/tag/6.1.0
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.
Yaaas thank you!
src/Elastica/Client.php
Outdated
@@ -24,6 +24,8 @@ | |||
*/ | |||
class Client extends BaseClient | |||
{ | |||
private $forbiddenHttpCodes = [403, 404, 400]; |
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.
We should make this configurable.
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.
Agreed, let me implement this and add some tests
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.
Please note that by intercepting 404
you break various exists
functions in Elastica which send HEAD
requests and check for 200
vs 404
responses.
Elastica\Type::exists()
Elastica\Index::exists()
Elastica\IndexTemplate::exists()
Put in configuration instead of hard-coding in the Client class Unit test the configuration Defaults are 400, 403, 404 Refactor unit tests and mocks for the Client
src/Elastica/Client.php
Outdated
if (isset($transportInfo['http_code']) && in_array($transportInfo['http_code'], $forbiddenHttpCodes, true)) { | ||
$body = isset($transportInfo['body']) ? $transportInfo['body'] : 'blank'; | ||
$message = sprintf('Error in transportInfo: response code is %s, response body is %s', $transportInfo['http_code'], $body); | ||
throw new \Exception($message); |
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.
For debugging reasons we should throw a different exception. Maybe one of https://github.com/ruflin/Elastica/tree/master/lib/Elastica/Exception ? @ruflin ?
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.
SGTM. The part I'm worried here is that this could be a breaking change in Elastica? Want to open a PR against Elastica to discuss it there?
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.
Changed the exception from the global Exception to ClientException, good point!
Gents, thank you both so much for your help and let me know if something more is needed
Update unit test
@jandom The latest changes are OK, but some tests are still failing:
|
Yeah, you're right – let me have a look |
okay, i think i know what's going on – the test fail with the "prefer lowest" which causes the ruflin/elastica version 5.2.1 to be installed. The version obviously doesn't have the improvements I shipped – these are only present in the 6.x branch – I'd have to backport my changes into the other branch. @XWB is that what has to get done to get this over the line? |
Backported the changes to ruflin/Elastica 5.x branch – as far as I can tell this is the only way to get the CI green here |
Here is some discussion that lead to the latest commits ruflin/Elastica#1592 |
@ruflin thanks so much – yes that is correct! |
Here you go with the 6.1.1 release: https://github.com/ruflin/Elastica/releases/tag/6.1.1 |
@ruflin thank you so much #SparklesOfJoy #HappyTimes |
Updated the composer.json with the new dependency tags |
Thanks for all the effort guys :) |
Wooohooo, thanks to @XWB for closing 🎉 |
This PR attempts to address problem described in ruflin/Elastica#1508
Transport errors don't throw exceptions but are handled by ruflin/Elastica, however FOSElasticaBundle was never checking if there was a transport error detected by ruflin/Elastica
This PR goes hand-in-hand with the PR here, which improves NullTransport in ruflin/Elastica
ruflin/Elastica#1529