Skip to content

Commit ea0ee3b

Browse files
committed
update TODO on parsing exceptions back with a potential plan
1 parent 79a8454 commit ea0ee3b

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

core/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,12 @@ public static ElasticsearchException fromXContent(XContentParser parser) throws
508508
ElasticsearchException e = new ElasticsearchException(message.toString(), cause);
509509

510510
for (Map.Entry<String, List<String>> entry : metadata.entrySet()) {
511-
//TODO subclasses can print out additional metadata through metadataToXContent. Complex objects are not currently supported,
512-
//while key-value pairs are. Those become part of the metadata set and inherit the "es." prefix as that is currently required
513-
//by addMetadata. The prefix will get stripped out anyways when printing metadata out so it will be invisible.
514-
//The only potential problem would manifest if a parsed exception is serialized back to a version < 5.3.0 , then the additional
515-
//metadata would be sent back as es. response headers which is surprising. That said this never ever happens as exceptions
516-
//are only parsed in the high level REST client. Maybe this is a good reason to have parsing code for exceptions in the client
517-
//only, also because while response may moved out of core one day, exception most likely won't.
511+
//subclasses can print out additional metadata through the metadataToXContent method. Simple key-value pairs will be
512+
//parsed back and become part of this metadata set, while objects and arrays are not supported when parsing back.
513+
//Those key-value pairs become part of the metadata set and inherit the "es." prefix as that is currently required
514+
//by addMetadata. The prefix will get stripped out when printing metadata out so it will be effectively invisible.
515+
//TODO move subclasses that print out simple metadata to using addMetadata directly and support also numbers and booleans.
516+
//TODO rename metadataToXContent and have only SearchPhaseExecutionException use it, which prints out complex objects
518517
e.addMetadata("es." + entry.getKey(), entry.getValue());
519518
}
520519
for (Map.Entry<String, Object> header : headers.entrySet()) {

core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException {
523523
* be rendered like the REST API does when the "error_trace" parameter is set to true.
524524
*/
525525
private static void assertToXContentAsJson(ToXContent e, String expectedJson) throws IOException {
526-
BytesReference actual = XContentHelper.toXContent(e, XContentType.JSON);
526+
BytesReference actual = XContentHelper.toXContent(e, XContentType.JSON, randomBoolean());
527527
assertToXContentEquivalent(new BytesArray(expectedJson), actual, XContentType.JSON);
528528
}
529529

0 commit comments

Comments
 (0)