From 33b9e2065bf52853b59e319f9d69eded2171eff1 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Thu, 29 Sep 2016 11:34:52 +0200 Subject: [PATCH] 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. --- .../java/org/elasticsearch/ingest/ConfigurationUtils.java | 8 +++++++- .../ingest/common/ScriptProcessorFactoryTests.java | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java b/core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java index 908e3446980..88105420e14 100644 --- a/core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java +++ b/core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java @@ -224,7 +224,13 @@ public final class ConfigurationUtils { public static ElasticsearchException newConfigurationException(String processorType, String processorTag, 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); return exception; } diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java index ef517d986cb..27eeb80670a 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java @@ -56,7 +56,7 @@ public class ScriptProcessorFactoryTests extends ESTestCase { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> 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 { @@ -66,6 +66,6 @@ public class ScriptProcessorFactoryTests extends ESTestCase { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> 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")); } }