Skip to content

Commit 2d16e55

Browse files
Readd MappingUpdatedAction unwrapping of exceptions
Since ElasticsearchException.guessRootCause does not support wrapped non-ElasticsearchException, this causes a test failure in 7.x.
1 parent 2c85223 commit 2d16e55

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

server/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.action.index;
2121

22+
import org.elasticsearch.ElasticsearchException;
2223
import org.elasticsearch.action.ActionListener;
2324
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2425
import org.elasticsearch.action.support.master.MasterNodeRequest;
@@ -30,6 +31,8 @@
3031
import org.elasticsearch.common.settings.Setting.Property;
3132
import org.elasticsearch.common.settings.Settings;
3233
import org.elasticsearch.common.unit.TimeValue;
34+
import org.elasticsearch.common.util.concurrent.FutureUtils;
35+
import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException;
3336
import org.elasticsearch.common.xcontent.XContentType;
3437
import org.elasticsearch.index.Index;
3538
import org.elasticsearch.index.mapper.MapperService;
@@ -82,8 +85,21 @@ public void onResponse(AcknowledgedResponse acknowledgedResponse) {
8285

8386
@Override
8487
public void onFailure(Exception e) {
85-
listener.onFailure(e);
88+
listener.onFailure(unwrapException(e));
8689
}
8790
});
8891
}
92+
93+
// todo: this explicit unwrap should not be necessary, but is until guessRootCause is fixed to allow wrapped non-es exception.
94+
private static Exception unwrapException(Exception cause) {
95+
return cause instanceof ElasticsearchException ? unwrapEsException((ElasticsearchException) cause) : cause;
96+
}
97+
98+
private static RuntimeException unwrapEsException(ElasticsearchException esEx) {
99+
Throwable root = esEx.unwrapCause();
100+
if (root instanceof RuntimeException) {
101+
return (RuntimeException) root;
102+
}
103+
return new UncategorizedExecutionException("Failed execution", root);
104+
}
89105
}

0 commit comments

Comments
 (0)