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

Throw better exception on wrong dynamic_templates syntax #51783

Merged
merged 6 commits into from
Feb 4, 2020

Conversation

feifeiiiiiiiiiii
Copy link
Contributor

Fix issue #51486

@feifeiiiiiiiiiii
Copy link
Contributor Author

feifeiiiiiiiiiii commented Feb 1, 2020

CLA signature done !

@dliappis dliappis added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Feb 3, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@pugnascotia
Copy link
Contributor

@elasticmachine ok to test

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Hi @feifeiiiiiiiiiii, thanks for opening this PR. The change generally looks good to me, however I left two comments around a small style issue and the exception message. Also it would be good if you could add a test around this new exception to e.g. RootObjectMapperTests. You can take a look at "testDynamicTemplates" and either add another case there that checks for the exception (there is a nice expectThrows helper method in LuceneTestCase that makes this easy) or add a new test case for that.

@@ -168,6 +168,9 @@ protected boolean processField(RootObjectMapper.Builder builder, String fieldNam
}
]
*/
if (!(fieldNode instanceof List)) {
Copy link
Member

Choose a reason for hiding this comment

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

small style nit: can you use ((fieldNode instanceof List) == false) instead? We prefer that kind of more verbose state to the negate operator for better readability throughout the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbuescher ok I will fix for you suggest

@@ -168,6 +168,9 @@ protected boolean processField(RootObjectMapper.Builder builder, String fieldNam
}
]
*/
if (!(fieldNode instanceof List)) {
throw new MapperParsingException("Dynamic template syntax error");
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be good to provide some more information the user what went wrong. In this case it would be great to tell the user know that dynamic_templates expects an array of named objects or something along those lines.

@cbuescher cbuescher self-assigned this Feb 3, 2020
@cbuescher cbuescher changed the title Fix issue #51486 Throw better exception on wrong dynamic_templates syntax Feb 3, 2020
assertEquals("Dynamic template syntax error, expects an array of named objects", e.getMessage());
}
}

}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

This closing bracket is too much now, class closed in line 203 already so the test doesn't compile. Please remove the last two lines so the class compiles.

@cbuescher
Copy link
Member

@feifeiiiiiiiiiii thanks for adding the test. Unfortunately the test class doesn't compile now, I also left a small note regarding the exception message. Otherwise looks good, please correct these two things so we can merge once the CI tests pass.

@feifeiiiiiiiiiii
Copy link
Contributor Author

@cbuescher sorry my mistake

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for submitting this PR, will merge.

@cbuescher cbuescher merged commit 7e85fc4 into elastic:master Feb 4, 2020
cbuescher pushed a commit that referenced this pull request Feb 4, 2020
Currently, a mappings update request, where dynamic_mappings is an object
instead of an array, results in a http response with a 500 code. This PR checks
for this condition and throws a MapperParsingException like we do for other
malformed mapping cases.

Closes #51486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types v7.7.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants