Skip to content

Commit 4d42a4e

Browse files
authored
fix: throw io exception instead of storage exception (#229)
* fix: throw io exception instead of storage exception * fix: throw io exception instead of storage exception
1 parent 1bb5787 commit 4d42a4e

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public Tuple<String, byte[]> call() {
133133
if (result.y().length > 0 && lastEtag != null && !Objects.equals(result.x(), lastEtag)) {
134134
StringBuilder messageBuilder = new StringBuilder();
135135
messageBuilder.append("Blob ").append(blob).append(" was updated while reading");
136-
throw new StorageException(0, messageBuilder.toString());
136+
throw new IOException(messageBuilder.toString());
137137
}
138138
lastEtag = result.x();
139139
buffer = result.y();
140140
} catch (RetryHelper.RetryHelperException e) {
141-
throw StorageException.translateAndThrow(e);
141+
throw new IOException(e);
142142
}
143143
if (toRead > buffer.length) {
144144
endOfStream = true;

google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.easymock.EasyMock.verify;
2424
import static org.junit.Assert.assertArrayEquals;
2525
import static org.junit.Assert.assertEquals;
26+
import static org.junit.Assert.assertFalse;
2627
import static org.junit.Assert.assertTrue;
2728
import static org.junit.Assert.fail;
2829

@@ -71,7 +72,7 @@ public void setUp() {
7172
}
7273

7374
@After
74-
public void tearDown() throws Exception {
75+
public void tearDown() {
7576
verify(rpcFactoryMock, storageRpcMock);
7677
}
7778

@@ -154,7 +155,7 @@ public void testClose() {
154155
reader = new BlobReadChannel(options, BLOB_ID, EMPTY_RPC_OPTIONS);
155156
assertTrue(reader.isOpen());
156157
reader.close();
157-
assertTrue(!reader.isOpen());
158+
assertFalse(reader.isOpen());
158159
}
159160

160161
@Test
@@ -190,7 +191,7 @@ public void testReadGenerationChanged() throws IOException {
190191
try {
191192
reader.read(secondReadBuffer);
192193
fail("Expected ReadChannel read to throw StorageException");
193-
} catch (StorageException ex) {
194+
} catch (IOException ex) {
194195
StringBuilder messageBuilder = new StringBuilder();
195196
messageBuilder.append("Blob ").append(blobId).append(" was updated while reading");
196197
assertEquals(messageBuilder.toString(), ex.getMessage());

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,22 +1751,22 @@ public void testReadChannelFail() throws IOException {
17511751
storage.reader(blob.getBlobId(), Storage.BlobSourceOption.metagenerationMatch(-1L))) {
17521752
reader.read(ByteBuffer.allocate(42));
17531753
fail("StorageException was expected");
1754-
} catch (StorageException ex) {
1754+
} catch (IOException ex) {
17551755
// expected
17561756
}
17571757
try (ReadChannel reader =
17581758
storage.reader(blob.getBlobId(), Storage.BlobSourceOption.generationMatch(-1L))) {
17591759
reader.read(ByteBuffer.allocate(42));
17601760
fail("StorageException was expected");
1761-
} catch (StorageException ex) {
1761+
} catch (IOException ex) {
17621762
// expected
17631763
}
17641764
BlobId blobIdWrongGeneration = BlobId.of(BUCKET, blobName, -1L);
17651765
try (ReadChannel reader =
17661766
storage.reader(blobIdWrongGeneration, Storage.BlobSourceOption.generationMatch())) {
17671767
reader.read(ByteBuffer.allocate(42));
17681768
fail("StorageException was expected");
1769-
} catch (StorageException ex) {
1769+
} catch (IOException ex) {
17701770
// expected
17711771
}
17721772
}
@@ -1798,7 +1798,7 @@ public void testReadChannelFailUpdatedGeneration() throws IOException {
17981798
readBytes = ByteBuffer.allocate(chunkSize);
17991799
reader.read(readBytes);
18001800
fail("StorageException was expected");
1801-
} catch (StorageException ex) {
1801+
} catch (IOException ex) {
18021802
StringBuilder messageBuilder = new StringBuilder();
18031803
messageBuilder.append("Blob ").append(blob.getBlobId()).append(" was updated while reading");
18041804
assertEquals(messageBuilder.toString(), ex.getMessage());

0 commit comments

Comments
 (0)