Skip to content

Commit

Permalink
Optimize error message
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Binlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed Aug 8, 2024
1 parent 778f159 commit 2e4fdf5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1716,20 +1716,20 @@ 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.startObject("..").field("foo", 2).endObject(); }))
);

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 {
Expand Down

0 comments on commit 2e4fdf5

Please sign in to comment.