Skip to content

Commit 4943eef

Browse files
dr0imayya-sharipova
authored andcommitted
Log document id when MapperParsingException occurs (#37800)
Closes #37658
1 parent c01d98b commit 4943eef

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
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
@@ -299,8 +299,8 @@ public void parse(ParseContext context) throws IOException {
299299
context.doc().add(field);
300300
}
301301
} catch (Exception e) {
302-
throw new MapperParsingException("failed to parse field [{}] of type [{}]", e, fieldType().name(),
303-
fieldType().typeName());
302+
throw new MapperParsingException("failed to parse field [{}] of type [{}] in document with id '{}'", e, fieldType().name(),
303+
fieldType().typeName(), context.sourceToParse().id());
304304
}
305305
multiFields.parse(this, context);
306306
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void testParsesEs6BooleansStrict() throws IOException {
202202
.endObject());
203203
MapperParsingException ex = expectThrows(MapperParsingException.class,
204204
() -> defaultMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)));
205-
assertEquals("failed to parse field [field] of type [boolean]", ex.getMessage());
205+
assertEquals("failed to parse field [field] of type [boolean] in document with id '1'", ex.getMessage());
206206
}
207207

208208
public void testMultiFields() throws IOException {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ public void testUnexpectedFieldMappingType() throws Exception {
130130
.endObject());
131131
MapperException exception = expectThrows(MapperException.class,
132132
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
133-
assertThat(exception.getMessage(), containsString("failed to parse field [foo] of type [long]"));
133+
assertThat(exception.getMessage(), containsString("failed to parse field [foo] of type [long] in document with id '1'"));
134134
}
135135
{
136136
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("bar", "bar")
137137
.endObject());
138138
MapperException exception = expectThrows(MapperException.class,
139139
() -> mapper.parse(SourceToParse.source("test", "type", "2", bytes, XContentType.JSON)));
140-
assertThat(exception.getMessage(), containsString("failed to parse field [bar] of type [boolean]"));
140+
assertThat(exception.getMessage(), containsString("failed to parse field [bar] of type [boolean] in document with id '2'"));
141141
}
142142
{
143143
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("geo", 123)

0 commit comments

Comments
 (0)