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

Add the cause of failure to the stacktrace for the CRT-based S3 client #4640

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "AWS CRT-based S3 Client",
"contributor": "",
"description": "Add the cause of failure to the stacktrace if present for the AWS CRT-based S3 client. Related to [aws-crt-java#497](https://github.com/awslabs/aws-crt-java/issues/697)."
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<rxjava.version>2.2.21</rxjava.version>
<commons-codec.verion>1.15</commons-codec.verion>
<jmh.version>1.29</jmh.version>
<awscrt.version>0.27.7</awscrt.version>
<awscrt.version>0.28.0</awscrt.version>

<!--Test dependencies -->
<junit5.version>5.10.0</junit5.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ public int onResponseBody(ByteBuffer bodyBytesIn, long objectRangeStart, long ob
@Override
public void onFinished(S3FinishedResponseContext context) {
int crtCode = context.getErrorCode();
int responseStatus = context.getResponseStatus();
byte[] errorPayload = context.getErrorPayload();
if (crtCode != CRT.AWS_CRT_SUCCESS) {
handleError(crtCode, responseStatus, errorPayload);
handleError(context);
} else {
onSuccessfulResponseComplete();
}
Expand Down Expand Up @@ -127,13 +125,19 @@ public void cancelRequest() {
failResponseHandlerAndFuture(sdkClientException);
}

private void handleError(int crtCode, int responseStatus, byte[] errorPayload) {
private void handleError(S3FinishedResponseContext context) {
int crtCode = context.getErrorCode();
int responseStatus = context.getResponseStatus();
byte[] errorPayload = context.getErrorPayload();

if (isErrorResponse(responseStatus) && errorPayload != null) {
onErrorResponseComplete(errorPayload);
} else {
Throwable cause = context.getCause();

SdkClientException sdkClientException =
SdkClientException.create("Failed to send the request: " +
CRT.awsErrorString(crtCode));
CRT.awsErrorString(crtCode), cause);
failResponseHandlerAndFuture(sdkClientException);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ public void requestFailed_shouldCompleteFutureExceptionally() {
verify(s3MetaRequest).close();
}

@Test
public void requestFailedWithCause_shouldCompleteFutureExceptionallyWithCause() {
RuntimeException cause = new RuntimeException("error");
S3FinishedResponseContext s3FinishedResponseContext = stubResponseContext(1, 0, null);
when(s3FinishedResponseContext.getCause()).thenReturn(cause);

responseHandlerAdapter.onFinished(s3FinishedResponseContext);
Throwable actualException = sdkResponseHandler.error;
String message = "Failed to send the request";
assertThat(actualException).isInstanceOf(SdkClientException.class).hasMessageContaining(message);
assertThat(future).isCompletedExceptionally();

assertThatThrownBy(() -> future.join()).hasRootCause(cause).hasMessageContaining(message);
verify(s3MetaRequest).close();
}

private S3FinishedResponseContext stubResponseContext(int errorCode, int responseStatus, byte[] errorPayload) {
Mockito.reset(context);
when(context.getErrorCode()).thenReturn(errorCode);
Expand Down
Loading