Skip to content

Commit 1827cf9

Browse files
committed
Update exception thrown to SdkClientException, fix tests
1 parent 1e31a9b commit 1827cf9

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/async/FileAsyncRequestBody.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.awssdk.core.async.AsyncRequestBodySplitConfiguration;
3737
import software.amazon.awssdk.core.async.CloseableAsyncRequestBody;
3838
import software.amazon.awssdk.core.async.SdkPublisher;
39+
import software.amazon.awssdk.core.exception.SdkClientException;
3940
import software.amazon.awssdk.core.internal.util.Mimetype;
4041
import software.amazon.awssdk.core.internal.util.NoopSubscription;
4142
import software.amazon.awssdk.utils.Logger;
@@ -469,31 +470,30 @@ private boolean validateFileUnchanged() {
469470
try {
470471
long sizeAtEnd = Files.size(path);
471472
if (sizeAtStart != sizeAtEnd) {
472-
signalOnError(new RuntimeException("File size changed after reading started. Initial size: "
473-
+ sizeAtStart + ". Current size: " + sizeAtEnd));
473+
signalOnError(SdkClientException.create("File size changed after reading started. Initial size: "
474+
+ sizeAtStart + ". Current size: " + sizeAtEnd));
474475
return false;
475476
}
476477

477478
if (remainingBytes.get() > 0) {
478-
signalOnError(new RuntimeException("Fewer bytes were read than were expected, was the file modified after "
479-
+ "reading started?"));
479+
signalOnError(SdkClientException.create("Fewer bytes were read than were expected, was the file modified "
480+
+ "after reading started?"));
480481
return false;
481482
}
482483

483484
FileTime modifiedTimeAtEnd = Files.getLastModifiedTime(path);
484485
if (modifiedTimeAtStart.compareTo(modifiedTimeAtEnd) != 0) {
485-
signalOnError(
486-
new RuntimeException("File last-modified time changed after reading started. Initial modification "
487-
+ "time: " + modifiedTimeAtStart + ". Current modification time: " +
488-
modifiedTimeAtEnd));
486+
signalOnError(SdkClientException.create("File last-modified time changed after reading started. "
487+
+ "Initial modification time: " + modifiedTimeAtStart
488+
+ ". Current modification time: " + modifiedTimeAtEnd));
489489
return false;
490490
}
491491
} catch (NoSuchFileException e) {
492-
signalOnError(new IOException("Unable to check file status after read. Was the file deleted or were its "
493-
+ "permissions changed?", e));
492+
signalOnError(SdkClientException.create("Unable to check file status after read. Was the file deleted"
493+
+ " or were its permissions changed?", e));
494494
return false;
495495
} catch (IOException e) {
496-
signalOnError(new IOException("Unable to check file status after read.", e));
496+
signalOnError(SdkClientException.create("Unable to check file status after read.", e));
497497
return false;
498498
}
499499
return true;

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/async/FileAsyncRequestBodyTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.reactivestreams.Subscriber;
4141
import org.reactivestreams.Subscription;
4242
import software.amazon.awssdk.core.async.AsyncRequestBody;
43+
import software.amazon.awssdk.core.exception.SdkClientException;
4344
import software.amazon.awssdk.testutils.RandomTempFile;
4445
import software.amazon.awssdk.utils.BinaryUtils;
4546

@@ -128,7 +129,7 @@ public void changingFile_fileGetsShorterThanAlreadyRead_failsBecauseTooShort() t
128129
subscriber.sub.request(Long.MAX_VALUE);
129130

130131
assertThatThrownBy(() -> subscriber.completed.get(5, TimeUnit.SECONDS))
131-
.hasCauseInstanceOf(IOException.class);
132+
.hasCauseInstanceOf(SdkClientException.class);
132133
}
133134

134135
@Test
@@ -154,7 +155,7 @@ public void changingFile_fileGetsShorterThanExistingLength_failsBecauseTooShort(
154155
subscriber.sub.request(Long.MAX_VALUE);
155156

156157
assertThatThrownBy(() -> subscriber.completed.get(5, TimeUnit.SECONDS))
157-
.hasCauseInstanceOf(IOException.class);
158+
.hasCauseInstanceOf(SdkClientException.class);
158159
}
159160

160161
@Test
@@ -180,7 +181,7 @@ public void changingFile_fileGetsLongerThanExistingLength_failsBecauseTooLong()
180181
subscriber.sub.request(Long.MAX_VALUE);
181182

182183
assertThatThrownBy(() -> subscriber.completed.get(5, TimeUnit.SECONDS))
183-
.hasCauseInstanceOf(IOException.class);
184+
.hasCauseInstanceOf(SdkClientException.class);
184185
}
185186

186187
@Test
@@ -204,7 +205,7 @@ public void changingFile_fileGetsTouched_failsBecauseUpdatedModificationTime() t
204205
subscriber.sub.request(Long.MAX_VALUE);
205206

206207
assertThatThrownBy(() -> subscriber.completed.get(5, TimeUnit.SECONDS))
207-
.hasCauseInstanceOf(IOException.class);
208+
.hasCauseInstanceOf(SdkClientException.class);
208209
}
209210

210211
@Test
@@ -227,7 +228,7 @@ public void changingFile_fileGetsDeleted_failsBecauseDeleted() throws Exception
227228
subscriber.sub.request(Long.MAX_VALUE);
228229

229230
assertThatThrownBy(() -> subscriber.completed.get(5, TimeUnit.SECONDS))
230-
.hasCauseInstanceOf(IOException.class);
231+
.hasCauseInstanceOf(SdkClientException.class);
231232
}
232233

233234
@Test

0 commit comments

Comments
 (0)