Skip to content

Commit 9aeffb9

Browse files
committed
Additional keep stack trace extension method calls
1 parent ab20ebb commit 9aeffb9

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/Nest/ElasticClient-Search.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ public Task<ISearchResponse<TResult>> SearchAsync<T, TResult>(Func<SearchDescrip
7575

7676
return this.RawDispatch.SearchDispatchAsync<SearchResponse<TResult>>(pathInfo, descriptor)
7777
.ContinueWith<ISearchResponse<TResult>>(t => {
78-
if (t.IsFaulted)
79-
throw t.Exception.Flatten().InnerException;
78+
if (t.IsFaulted && t.Exception != null)
79+
{
80+
t.Exception.Flatten().InnerException.RethrowKeepingStackTrace();
81+
return null; //won't be hit
82+
}
8083

8184
return t.Result.Success
8285
? t.Result.Response
@@ -101,8 +104,11 @@ public Task<ISearchResponse<TResult>> SearchAsync<T, TResult>(ISearchRequest req
101104

102105
return this.RawDispatch.SearchDispatchAsync<SearchResponse<TResult>>(pathInfo, request)
103106
.ContinueWith<ISearchResponse<TResult>>(t => {
104-
if (t.IsFaulted)
105-
throw t.Exception.Flatten().InnerException;
107+
if (t.IsFaulted && t.Exception != null)
108+
{
109+
t.Exception.Flatten().InnerException.RethrowKeepingStackTrace();
110+
return null; //won't be hit
111+
}
106112

107113
return t.Result.Success
108114
? t.Result.Response

src/Nest/ElasticClient-SearchTemplate.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ public Task<ISearchResponse<TResult>> SearchTemplateAsync<T, TResult>(Func<Searc
6969
return this.RawDispatch.SearchTemplateDispatchAsync<SearchResponse<TResult>>(pathInfo, descriptor)
7070
.ContinueWith<ISearchResponse<TResult>>(t =>
7171
{
72-
if (t.IsFaulted)
73-
throw t.Exception.Flatten().InnerException;
72+
if (t.IsFaulted && t.Exception != null)
73+
{
74+
t.Exception.Flatten().InnerException.RethrowKeepingStackTrace();
75+
return null; //won't be hit
76+
}
7477

7578
return t.Result.Success
7679
? t.Result.Response
@@ -94,8 +97,11 @@ public Task<ISearchResponse<TResult>> SearchTemplateAsync<T, TResult>(ISearchTem
9497
return this.RawDispatch.SearchTemplateDispatchAsync<SearchResponse<TResult>>(pathInfo, request)
9598
.ContinueWith<ISearchResponse<TResult>>(t =>
9699
{
97-
if (t.IsFaulted)
98-
throw t.Exception.Flatten().InnerException;
100+
if (t.IsFaulted && t.Exception != null)
101+
{
102+
t.Exception.Flatten().InnerException.RethrowKeepingStackTrace();
103+
return null; //won't be hit
104+
}
99105

100106
return t.Result.Success
101107
? t.Result.Response

0 commit comments

Comments
 (0)