Skip to content

Commit

Permalink
Errors should not be wrapped - Async Waiters (#3430)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidh44 committed Sep 21, 2022
1 parent 821397a commit 5951f6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -104,10 +104,21 @@ private void runAsyncPollingFunction(Supplier<CompletableFuture<T>> asyncPolling
future.completeExceptionally(new UnsupportedOperationException());
}
} else {
future.completeExceptionally(executorHelper.noneMatchException(responseOrException));
Optional<Throwable> t = responseOrException.right();
if (t.isPresent() && t.get() instanceof Error) {
future.completeExceptionally(t.get());
} else {
future.completeExceptionally(executorHelper.noneMatchException(responseOrException));
}
}
} catch (Throwable t) {
future.completeExceptionally(SdkClientException.create("Encountered unexpected exception.", t));
Throwable cause = t instanceof CompletionException ? t.getCause() : t;

if (cause instanceof Error) {
future.completeExceptionally(cause);
} else {
future.completeExceptionally(SdkClientException.create("Encountered unexpected exception.", cause));
}
}
});
}
Expand Down
Expand Up @@ -198,6 +198,13 @@ public void failureException_shouldThrowException() {
.hasCauseInstanceOf(SdkClientException.class);
}

@Test
void errorShouldNotBeWrapped() {
when(asyncClient.allTypes(any(AllTypesRequest.class))).thenReturn(CompletableFutureUtils.failedFuture(new OutOfMemoryError()));
assertThatThrownBy(() -> asyncWaiter.waitUntilAllTypesSuccess(SdkBuilder::build).join())
.hasCauseInstanceOf(Error.class);
}

@Test
public void closeWaiterCreatedWithClient_clientDoesNotClose() {
asyncWaiter.close();
Expand Down

0 comments on commit 5951f6b

Please sign in to comment.