19
19
import org .opensearch .search .internal .SearchContext ;
20
20
import org .opensearch .search .profile .query .ProfileCollectorManager ;
21
21
import org .opensearch .search .query .QueryPhase .DefaultQueryPhaseSearcher ;
22
- import org .opensearch .tasks .TaskCancelledException ;
23
- import org .opensearch .transport .TransportException ;
24
22
25
23
import java .io .IOException ;
26
24
import java .util .LinkedList ;
@@ -92,17 +90,12 @@ private static boolean searchWithCollectorManager(
92
90
if (re .getCause () instanceof ExecutionException || re .getCause () instanceof InterruptedException ) {
93
91
Throwable t = re .getCause ();
94
92
if (t .getCause () != null ) {
95
- if (t .getCause () instanceof TransportException ) {
96
- throw (TransportException ) t .getCause ();
97
- }
98
- if (t .getCause () instanceof TaskCancelledException ) {
99
- throw (TaskCancelledException ) t .getCause ();
100
- }
93
+ rethrow (t .getCause ());
101
94
}
102
95
}
103
96
104
97
// Rethrow any unexpected exception types
105
- throw re ;
98
+ rethrow ( re . getCause ()) ;
106
99
}
107
100
if (searchContext .isSearchTimedOut ()) {
108
101
assert timeoutSet : "TimeExceededException thrown even though timeout wasn't set" ;
@@ -122,4 +115,9 @@ private static boolean searchWithCollectorManager(
122
115
public AggregationProcessor aggregationProcessor (SearchContext searchContext ) {
123
116
return aggregationProcessor ;
124
117
}
118
+
119
+ @ SuppressWarnings ("unchecked" )
120
+ private static <T extends Throwable > RuntimeException rethrow (Throwable throwable ) throws T {
121
+ throw (T ) throwable ; // naively cast to unchecked exception
122
+ }
125
123
}
0 commit comments