Skip to content
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

Fix #977: Handle the exception as structured even if the reason is null #980

Merged
merged 4 commits into from
Dec 19, 2019

Conversation

oogFranz
Copy link
Contributor

@oogFranz oogFranz commented Dec 3, 2019

Close #977
The case of the issue #977 is handling structured exception as semi-structured exception which only occurs before Elasticsearch 2.0.

Ordinal code checks whether $error['error']['reason'] is set.

if (isset($error['error']['reason']) === true) {

Unfortunately, master_not_discovered_exception is thrown with blank error reason.
https://github.com/elastic/elasticsearch/blob/16bfdcacc0172264db9b32aa6edfa8b5c327f3b4/server/src/main/java/org/elasticsearch/discovery/MasterNotDiscoveredException.java#L31

To avoid the problem, use array_key_exists() alter isset().
To make the logic simple, I refactored the if-statements.
Check whether the exception is structured or not first.
Then distinguish whether the exception is structured exception after Elasticsearch 2.0.

@ezimuel
Copy link
Contributor

ezimuel commented Dec 19, 2019

@oogFranz I added a unit test to cover the #977 issue and I applied an extra json_encode() to be more defensive for future changes. Thanks for your contribution!

@ezimuel ezimuel merged commit f148afa into elastic:master Dec 19, 2019
@oogFranz oogFranz deleted the fix/977_2 branch December 23, 2019 10:55
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.

master_not_discovered_exception results in the following fatal error:
2 participants