Skip to content

Commit a3d9ba3

Browse files
dr0imayya-sharipova
authored andcommitted
Log document id when MapperParsingException occurs (#37800)
Closes #37658
1 parent 5b008a3 commit a3d9ba3

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ public void parse(ParseContext context) throws IOException {
276276
context.doc().add(field);
277277
}
278278
} catch (Exception e) {
279-
throw new MapperParsingException("failed to parse field [{}] of type [{}]", e, fieldType().name(),
280-
fieldType().typeName());
279+
throw new MapperParsingException("failed to parse field [{}] of type [{}] in document with id '{}'", e, fieldType().name(),
280+
fieldType().typeName(), context.sourceToParse().id());
281281
}
282282
multiFields.parse(this, context);
283283
}

server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void testParsesBooleansStrict() throws IOException {
142142
.endObject());
143143
MapperParsingException ex = expectThrows(MapperParsingException.class,
144144
() -> defaultMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON)));
145-
assertEquals("failed to parse field [field] of type [boolean]", ex.getMessage());
145+
assertEquals("failed to parse field [field] of type [boolean] in document with id '1'", ex.getMessage());
146146
}
147147

148148
public void testMultiFields() throws IOException {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,21 @@ public void testUnexpectedFieldMappingType() throws Exception {
139139
.endObject());
140140
MapperException exception = expectThrows(MapperException.class,
141141
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
142-
assertThat(exception.getMessage(), containsString("failed to parse field [foo] of type [long]"));
142+
assertThat(exception.getMessage(), containsString("failed to parse field [foo] of type [long] in document with id '1'"));
143143
}
144144
{
145145
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("bar", "bar")
146146
.endObject());
147147
MapperException exception = expectThrows(MapperException.class,
148148
() -> mapper.parse(new SourceToParse("test", "type", "2", bytes, XContentType.JSON)));
149-
assertThat(exception.getMessage(), containsString("failed to parse field [bar] of type [boolean]"));
149+
assertThat(exception.getMessage(), containsString("failed to parse field [bar] of type [boolean] in document with id '2'"));
150150
}
151151
{
152152
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("geo", 123)
153153
.endObject());
154154
MapperException exception = expectThrows(MapperException.class,
155155
() -> mapper.parse(new SourceToParse("test", "type", "2", bytes, XContentType.JSON)));
156-
assertThat(exception.getMessage(), containsString("failed to parse field [geo] of type [geo_shape]"));
156+
assertThat(exception.getMessage(), containsString("failed to parse field [geo]"));
157157
}
158158

159159
}

0 commit comments

Comments
 (0)