Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors should not be wrapped - Async Waiters #3430

Merged
merged 2 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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