no null values in ingest configuration error messages (#20616)

The invalid ingest configuration field name used to show itself,
even when it was null, in error messages. Sometimes this does not make
sense.

e.g.
```[null] Only one of [file], [id], or [inline] may be configure```
vs.
```Only one of [file], [id], or [inline] may be configure```

The above deals with three fields, therefore this no one property
responsible.
This commit is contained in:
Tal Levy 2016-09-29 11:34:52 +02:00 committed by GitHub
parent 74184cb1b0
commit 33b9e2065b
2 changed files with 9 additions and 3 deletions

View File

@ -224,7 +224,13 @@ public final class ConfigurationUtils {
public static ElasticsearchException newConfigurationException(String processorType, String processorTag, public static ElasticsearchException newConfigurationException(String processorType, String processorTag,
String propertyName, String reason) { String propertyName, String reason) {
ElasticsearchParseException exception = new ElasticsearchParseException("[" + propertyName + "] " + reason); String msg;
if (propertyName == null) {
msg = reason;
} else {
msg = "[" + propertyName + "] " + reason;
}
ElasticsearchParseException exception = new ElasticsearchParseException(msg);
addHeadersToException(exception, processorType, processorTag, propertyName); addHeadersToException(exception, processorType, processorTag, propertyName);
return exception; return exception;
} }

View File

@ -56,7 +56,7 @@ public class ScriptProcessorFactoryTests extends ESTestCase {
ElasticsearchException exception = expectThrows(ElasticsearchException.class, ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> factory.create(null, randomAsciiOfLength(10), configMap)); () -> factory.create(null, randomAsciiOfLength(10), configMap));
assertThat(exception.getMessage(), is("[null] Only one of [file], [id], or [inline] may be configured")); assertThat(exception.getMessage(), is("Only one of [file], [id], or [inline] may be configured"));
} }
public void testFactoryValidationAtLeastOneScriptingType() throws Exception { public void testFactoryValidationAtLeastOneScriptingType() throws Exception {
@ -66,6 +66,6 @@ public class ScriptProcessorFactoryTests extends ESTestCase {
ElasticsearchException exception = expectThrows(ElasticsearchException.class, ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> factory.create(null, randomAsciiOfLength(10), configMap)); () -> factory.create(null, randomAsciiOfLength(10), configMap));
assertThat(exception.getMessage(), is("[null] Need [file], [id], or [inline] parameter to refer to scripts")); assertThat(exception.getMessage(), is("Need [file], [id], or [inline] parameter to refer to scripts"));
} }
} }