|
19 | 19 |
|
20 | 20 | package org.elasticsearch.cluster.action.index; |
21 | 21 |
|
| 22 | +import org.elasticsearch.ElasticsearchException; |
22 | 23 | import org.elasticsearch.action.ActionListener; |
23 | 24 | import org.elasticsearch.action.support.master.AcknowledgedResponse; |
24 | 25 | import org.elasticsearch.action.support.master.MasterNodeRequest; |
|
30 | 31 | import org.elasticsearch.common.settings.Setting.Property; |
31 | 32 | import org.elasticsearch.common.settings.Settings; |
32 | 33 | import org.elasticsearch.common.unit.TimeValue; |
| 34 | +import org.elasticsearch.common.util.concurrent.FutureUtils; |
| 35 | +import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException; |
33 | 36 | import org.elasticsearch.common.xcontent.XContentType; |
34 | 37 | import org.elasticsearch.index.Index; |
35 | 38 | import org.elasticsearch.index.mapper.MapperService; |
@@ -82,8 +85,21 @@ public void onResponse(AcknowledgedResponse acknowledgedResponse) { |
82 | 85 |
|
83 | 86 | @Override |
84 | 87 | public void onFailure(Exception e) { |
85 | | - listener.onFailure(e); |
| 88 | + listener.onFailure(unwrapException(e)); |
86 | 89 | } |
87 | 90 | }); |
88 | 91 | } |
| 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 | + } |
89 | 105 | } |
0 commit comments