Skip to content

Commit 2e4fdf5

Browse files
committed
Optimize error message
Signed-off-by: Gao Binlong <[email protected]>
1 parent 778f159 commit 2e4fdf5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

rest-api-spec/src/main/resources/rest-api-spec/test/index/120_field_name.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
index: test_1
1010

1111
- do:
12-
catch: /field name cannot contain only dot/
12+
catch: /field name cannot contain only the character \[.\]/
1313
index:
1414
index: test_1
1515
id: 1
@@ -18,7 +18,7 @@
1818
}
1919

2020
- do:
21-
catch: /field name cannot contain only dot/
21+
catch: /field name cannot contain only the character \[.\]/
2222
index:
2323
index: test_1
2424
id: 1
@@ -27,7 +27,7 @@
2727
}
2828

2929
- do:
30-
catch: /field name cannot contain only dot/
30+
catch: /field name cannot contain only the character \[.\]/
3131
index:
3232
index: test_1
3333
id: 1

server/src/main/java/org/opensearch/index/mapper/DocumentParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static String[] splitAndValidatePath(String fullFieldPath) {
207207
if (fullFieldPath.contains(".")) {
208208
String[] parts = fullFieldPath.split("\\.");
209209
if (parts.length == 0) {
210-
throw new IllegalArgumentException("field name cannot contain only dot");
210+
throw new IllegalArgumentException("field name cannot contain only the character [.]");
211211
}
212212
for (String part : parts) {
213213
if (Strings.hasText(part) == false) {

server/src/test/java/org/opensearch/index/mapper/DocumentParserTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,20 +1716,20 @@ public void testDynamicFieldsWithOnlyDot() throws Exception {
17161716
})));
17171717

17181718
assertThat(e.getCause(), notNullValue());
1719-
assertThat(e.getCause().getMessage(), containsString("field name cannot contain only dot"));
1719+
assertThat(e.getCause().getMessage(), containsString("field name cannot contain only the character [.]"));
17201720

17211721
e = expectThrows(
17221722
MapperParsingException.class,
17231723
() -> mapper.parse(source(b -> { b.startObject("..").field("foo", 2).endObject(); }))
17241724
);
17251725

17261726
assertThat(e.getCause(), notNullValue());
1727-
assertThat(e.getCause().getMessage(), containsString("field name cannot contain only dot"));
1727+
assertThat(e.getCause().getMessage(), containsString("field name cannot contain only the character [.]"));
17281728

17291729
e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.field(".", "1234"))));
17301730

17311731
assertThat(e.getCause(), notNullValue());
1732-
assertThat(e.getCause().getMessage(), containsString("field name cannot contain only dot"));
1732+
assertThat(e.getCause().getMessage(), containsString("field name cannot contain only the character [.]"));
17331733
}
17341734

17351735
public void testDynamicFieldsEmptyName() throws Exception {

0 commit comments

Comments
 (0)