From 2e4fdf595ba1e5ba7b8cf92867261de90a8aab37 Mon Sep 17 00:00:00 2001 From: Gao Binlong Date: Thu, 8 Aug 2024 11:50:19 +0800 Subject: [PATCH] Optimize error message Signed-off-by: Gao Binlong --- .../resources/rest-api-spec/test/index/120_field_name.yml | 6 +++--- .../java/org/opensearch/index/mapper/DocumentParser.java | 2 +- .../org/opensearch/index/mapper/DocumentParserTests.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/index/120_field_name.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/index/120_field_name.yml index 181a5589ffb02..dae1da9963b0d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/index/120_field_name.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/index/120_field_name.yml @@ -9,7 +9,7 @@ index: test_1 - do: - catch: /field name cannot contain only dot/ + catch: /field name cannot contain only the character \[.\]/ index: index: test_1 id: 1 @@ -18,7 +18,7 @@ } - do: - catch: /field name cannot contain only dot/ + catch: /field name cannot contain only the character \[.\]/ index: index: test_1 id: 1 @@ -27,7 +27,7 @@ } - do: - catch: /field name cannot contain only dot/ + catch: /field name cannot contain only the character \[.\]/ index: index: test_1 id: 1 diff --git a/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java b/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java index 8dfa8ff4996ba..b03026d560dbf 100644 --- a/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java +++ b/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java @@ -207,7 +207,7 @@ private static String[] splitAndValidatePath(String fullFieldPath) { if (fullFieldPath.contains(".")) { String[] parts = fullFieldPath.split("\\."); if (parts.length == 0) { - throw new IllegalArgumentException("field name cannot contain only dot"); + throw new IllegalArgumentException("field name cannot contain only the character [.]"); } for (String part : parts) { if (Strings.hasText(part) == false) { diff --git a/server/src/test/java/org/opensearch/index/mapper/DocumentParserTests.java b/server/src/test/java/org/opensearch/index/mapper/DocumentParserTests.java index e183885416c3a..c9763d634979b 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DocumentParserTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DocumentParserTests.java @@ -1716,7 +1716,7 @@ public void testDynamicFieldsWithOnlyDot() throws Exception { }))); assertThat(e.getCause(), notNullValue()); - assertThat(e.getCause().getMessage(), containsString("field name cannot contain only dot")); + assertThat(e.getCause().getMessage(), containsString("field name cannot contain only the character [.]")); e = expectThrows( MapperParsingException.class, @@ -1724,12 +1724,12 @@ public void testDynamicFieldsWithOnlyDot() throws Exception { ); assertThat(e.getCause(), notNullValue()); - assertThat(e.getCause().getMessage(), containsString("field name cannot contain only dot")); + assertThat(e.getCause().getMessage(), containsString("field name cannot contain only the character [.]")); e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.field(".", "1234")))); assertThat(e.getCause(), notNullValue()); - assertThat(e.getCause().getMessage(), containsString("field name cannot contain only dot")); + assertThat(e.getCause().getMessage(), containsString("field name cannot contain only the character [.]")); } public void testDynamicFieldsEmptyName() throws Exception {