Skip to content

Commit 5af29f8

Browse files
authored
Improve error message when checksum validation fails. Make such failures retryable. (#2798)
1 parent cea7a9f commit 5af29f8

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

services/s3/src/main/java/software/amazon/awssdk/services/s3/checksums/ChecksumValidatingInputStream.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Arrays;
2121
import software.amazon.awssdk.annotations.SdkInternalApi;
2222
import software.amazon.awssdk.core.checksums.SdkChecksum;
23-
import software.amazon.awssdk.core.exception.SdkClientException;
23+
import software.amazon.awssdk.core.exception.RetryableException;
2424
import software.amazon.awssdk.http.Abortable;
2525
import software.amazon.awssdk.utils.BinaryUtils;
2626

@@ -169,9 +169,10 @@ private void validateAndThrow() {
169169
}
170170

171171
if (!Arrays.equals(computedChecksum, streamChecksum)) {
172-
throw SdkClientException.builder().message(
173-
String.format("Data read has a different checksum than expected. Was 0x%s, but expected 0x%s",
174-
BinaryUtils.toHex(computedChecksum), BinaryUtils.toHex(streamChecksum))).build();
172+
throw RetryableException.create(
173+
String.format("Data read has a different checksum than expected. Was 0x%s, but expected 0x%s. " +
174+
"This commonly means that the data was corrupted between the client and " +
175+
"service.", BinaryUtils.toHex(computedChecksum), BinaryUtils.toHex(streamChecksum)));
175176
}
176177
}
177178

services/s3/src/main/java/software/amazon/awssdk/services/s3/checksums/ChecksumValidatingPublisher.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import software.amazon.awssdk.annotations.SdkInternalApi;
2626
import software.amazon.awssdk.core.async.SdkPublisher;
2727
import software.amazon.awssdk.core.checksums.SdkChecksum;
28-
import software.amazon.awssdk.core.exception.SdkClientException;
28+
import software.amazon.awssdk.core.exception.RetryableException;
2929
import software.amazon.awssdk.utils.BinaryUtils;
3030

3131
@SdkInternalApi
@@ -134,8 +134,13 @@ public void onComplete() {
134134
if (strippedLength > 0) {
135135
byte[] computedChecksum = sdkChecksum.getChecksumBytes();
136136
if (!Arrays.equals(computedChecksum, streamChecksum)) {
137-
onError(SdkClientException.create(
138-
String.format("Data read has a different checksum than expected. Was 0x%s, but expected 0x%s",
137+
onError(RetryableException.create(
138+
String.format("Data read has a different checksum than expected. Was 0x%s, but expected 0x%s. "
139+
+ "Common causes: (1) You modified a request ByteBuffer before it could be "
140+
+ "written to the service. Please ensure your data source does not modify the "
141+
+ " byte buffers after you pass them to the SDK. (2) The data was corrupted between the "
142+
+ "client and service. Note: Despite this error, the upload still completed and was "
143+
+ "persisted in S3.",
139144
BinaryUtils.toHex(computedChecksum), BinaryUtils.toHex(streamChecksum))));
140145
return; // Return after onError and not call onComplete below
141146
}

services/s3/src/main/java/software/amazon/awssdk/services/s3/checksums/ChecksumsEnabledValidator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import software.amazon.awssdk.core.ClientType;
2828
import software.amazon.awssdk.core.SdkRequest;
2929
import software.amazon.awssdk.core.checksums.SdkChecksum;
30-
import software.amazon.awssdk.core.exception.SdkClientException;
30+
import software.amazon.awssdk.core.exception.RetryableException;
3131
import software.amazon.awssdk.core.interceptor.ExecutionAttribute;
3232
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
3333
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
@@ -144,8 +144,10 @@ public static void validatePutObjectChecksum(PutObjectResponse response, Executi
144144
byte[] ssHash = Base16Lower.decode(response.eTag().replace("\"", ""));
145145

146146
if (!Arrays.equals(digest, ssHash)) {
147-
throw SdkClientException.create(
148-
String.format("Data read has a different checksum than expected. Was 0x%s, but expected 0x%s",
147+
throw RetryableException.create(
148+
String.format("Data read has a different checksum than expected. Was 0x%s, but expected 0x%s. " +
149+
"This commonly means that the data was corrupted between the client and " +
150+
"service. Note: Despite this error, the upload still completed and was persisted in S3.",
149151
BinaryUtils.toHex(digest), BinaryUtils.toHex(ssHash)));
150152
}
151153
}

0 commit comments

Comments
 (0)