Skip to content

Storage Error Codes for Copies #45394

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

Merged
merged 5 commits into from
May 22, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/storage/azure-storage-blob",
"Tag": "java/storage/azure-storage-blob_e4ae407bc2"
"Tag": "java/storage/azure-storage-blob_636aa87a8b"
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public final class StorageError implements XmlSerializable<StorageError> {
*/
private String message;

/*
* The CopySourceStatusCode property.
*/
private Long copySourceStatusCode;

/*
* The CopySourceErrorCode property.
*/
private String copySourceErrorCode;

/*
* The CopySourceErrorMessage property.
*/
private String copySourceErrorMessage;

/**
* Creates an instance of StorageError class.
*/
Expand All @@ -49,6 +64,66 @@ public StorageError setMessage(String message) {
return this;
}

/**
* Get the copySourceStatusCode property: The CopySourceStatusCode property.
*
* @return the copySourceStatusCode value.
*/
public Long getCopySourceStatusCode() {
return this.copySourceStatusCode;
}

/**
* Set the copySourceStatusCode property: The CopySourceStatusCode property.
*
* @param copySourceStatusCode the copySourceStatusCode value to set.
* @return the StorageError object itself.
*/
public StorageError setCopySourceStatusCode(Long copySourceStatusCode) {
this.copySourceStatusCode = copySourceStatusCode;
return this;
}

/**
* Get the copySourceErrorCode property: The CopySourceErrorCode property.
*
* @return the copySourceErrorCode value.
*/
public String getCopySourceErrorCode() {
return this.copySourceErrorCode;
}

/**
* Set the copySourceErrorCode property: The CopySourceErrorCode property.
*
* @param copySourceErrorCode the copySourceErrorCode value to set.
* @return the StorageError object itself.
*/
public StorageError setCopySourceErrorCode(String copySourceErrorCode) {
this.copySourceErrorCode = copySourceErrorCode;
return this;
}

/**
* Get the copySourceErrorMessage property: The CopySourceErrorMessage property.
*
* @return the copySourceErrorMessage value.
*/
public String getCopySourceErrorMessage() {
return this.copySourceErrorMessage;
}

/**
* Set the copySourceErrorMessage property: The CopySourceErrorMessage property.
*
* @param copySourceErrorMessage the copySourceErrorMessage value to set.
* @return the StorageError object itself.
*/
public StorageError setCopySourceErrorMessage(String copySourceErrorMessage) {
this.copySourceErrorMessage = copySourceErrorMessage;
return this;
}

@Override
public XmlWriter toXml(XmlWriter xmlWriter) throws XMLStreamException {
return toXml(xmlWriter, null);
Expand All @@ -59,6 +134,9 @@ public XmlWriter toXml(XmlWriter xmlWriter, String rootElementName) throws XMLSt
rootElementName = CoreUtils.isNullOrEmpty(rootElementName) ? "StorageError" : rootElementName;
xmlWriter.writeStartElement(rootElementName);
xmlWriter.writeStringElement("Message", this.message);
xmlWriter.writeNumberElement("CopySourceStatusCode", this.copySourceStatusCode);
xmlWriter.writeStringElement("CopySourceErrorCode", this.copySourceErrorCode);
xmlWriter.writeStringElement("CopySourceErrorMessage", this.copySourceErrorMessage);
return xmlWriter.writeEndElement();
}

Expand Down Expand Up @@ -93,6 +171,12 @@ public static StorageError fromXml(XmlReader xmlReader, String rootElementName)

if ("Message".equals(elementName.getLocalPart())) {
deserializedStorageError.message = reader.getStringElement();
} else if ("CopySourceStatusCode".equals(elementName.getLocalPart())) {
deserializedStorageError.copySourceStatusCode = reader.getNullableElement(Long::parseLong);
} else if ("CopySourceErrorCode".equals(elementName.getLocalPart())) {
deserializedStorageError.copySourceErrorCode = reader.getStringElement();
} else if ("CopySourceErrorMessage".equals(elementName.getLocalPart())) {
deserializedStorageError.copySourceErrorMessage = reader.getStringElement();
} else {
reader.skipElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,20 @@ public void appendBlockFromURLMin() {
validateBasicHeaders(response.getHeaders());
}

/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@Test
public void appendBlockFromURLSourceErrorAndStatusCodeNewTest() {
AppendBlobClient destBlob = cc.getBlobClient(generateBlobName()).getAppendBlobClient();
destBlob.createIfNotExists();

BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));

assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
}*/

BlobStorageException e = assertThrows(BlobStorageException.class,
() -> destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));

assertTrue(e.getStatusCode() == 401);
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
assertTrue(e.getServiceMessage().contains("Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));

}

@Test
public void appendBlockFromURLRange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,19 +536,22 @@ public void appendBlockFromURLMin() {
}).verifyComplete();
}

/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@Test
public void appendBlockFromURLSourceErrorAndStatusCodeNewTest() {
AppendBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getAppendBlobAsyncClient();

StepVerifier.create(destBlob.createIfNotExists().then(destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES))))

StepVerifier
.create(destBlob.createIfNotExists()
.then(destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES))))
.verifyErrorSatisfies(r -> {
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
assertTrue(e.getStatusCode() == 401);
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
assertTrue(e.getServiceMessage().contains("Server failed to authenticate the request. Please refer to the information in the www-authenticate header"));

});
}*/
}

@Test
public void appendBlockFromURLRange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,17 +805,18 @@ public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, Stri
assertThrows(BlobStorageException.class, () -> bc.queryWithResponse(optionsOs, null, null));
}

/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@Test
public void copyFromURLSourceErrorAndStatusCode() {
BlockBlobClient destBlob = cc.getBlobClient(generateBlobName()).getBlockBlobClient();

BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.copyFromUrl(bc.getBlobUrl()));

assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
}*/

assertTrue(e.getStatusCode() == 401);
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
assertTrue(e.getServiceMessage().contains("Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));

}

static class MockProgressConsumer implements Consumer<BlobQueryProgress> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class BlobBaseAsyncApiTests extends BlobTestBase {
Expand Down Expand Up @@ -557,19 +558,19 @@ public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, Stri
StepVerifier.create(response).verifyError(BlobStorageException.class);
}

/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@Test
public void copyFromURLSourceErrorAndStatusCode() {
BlockBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getBlockBlobAsyncClient();
StepVerifier.create(destBlob.copyFromUrl(bc.getBlobUrl()))
.verifyErrorSatisfies(r -> {
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
});
}*/

StepVerifier.create(destBlob.copyFromUrl(bc.getBlobUrl())).verifyErrorSatisfies(r -> {
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
assertTrue(e.getStatusCode() == 401);
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
assertTrue(e.getServiceMessage().contains("Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));

});
}

static class MockProgressConsumer implements Consumer<BlobQueryProgress> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,21 @@ public void stageBlockFromUrl() {
assertEquals(ByteBuffer.wrap(outputStream.toByteArray()), DATA.getDefaultData());
}

/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@Test
public void stageBlockFromUrlSourceErrorAndStatusCode() {
BlockBlobClient destBlob = cc.getBlobClient(generateBlobName()).getBlockBlobClient();

String blockID = getBlockID();

BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.stageBlockFromUrl(blockID, blockBlobClient.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));

assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
}*/

BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.stageBlockFromUrl(blockID,
blockBlobClient.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));

assertTrue(e.getStatusCode() == 401);
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
assertTrue(e.getServiceMessage().contains("Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));

}

@Test
public void stageBlockFromUrlMin() {
Expand Down Expand Up @@ -1313,13 +1315,13 @@ private static Stream<Arguments> bufferedUploadSyncHandlePathingWithTransientFai
def numBlocks = data.remaining() / BlockBlobURL.MAX_STAGE_BLOCK_BYTES
long prevCount = 0
def mockReceiver = Mock(IProgressReceiver)


when:
TransferManager.uploadFromNonReplayableFlowable(Flowable.just(data), bu, BlockBlobURL.MAX_STAGE_BLOCK_BYTES, 10,
new TransferManagerUploadToBlockBlobOptions(mockReceiver, null, null, null, 20)).blockingGet()
data.position(0)

then:
// We should receive exactly one notification of the completed progress.
1 * mockReceiver.reportProgress(data.remaining()) */
Expand All @@ -1336,7 +1338,7 @@ private static Stream<Arguments> bufferedUploadSyncHandlePathingWithTransientFai
prevCount = bytesTransferred
}
}

// We should receive no notifications that report more progress than the size of the file.
0 * mockReceiver.reportProgress({ it > data.remaining() })
notThrown(IllegalArgumentException)
Expand Down Expand Up @@ -1453,9 +1455,9 @@ public void uploadFromUrlMin() {
@Test
public void uploadFromUrlSourceErrorAndStatusCode() {
BlockBlobClient destBlob = cc.getBlobClient(generateBlobName()).getBlockBlobClient();

BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.uploadFromUrl(blockBlobClient.getBlobUrl()));

assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,22 @@ public void stageBlockFromUrl() {
.verifyComplete();
}

/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@Test
public void stageBlockFromUrlSourceErrorAndStatusCode() {
BlockBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getBlockBlobAsyncClient();

String blockID = getBlockID();
StepVerifier.create(destBlob.stageBlockFromUrl(blockID, blockBlobAsyncClient.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)))
.verifyErrorSatisfies(r -> {

StepVerifier.create(destBlob.stageBlockFromUrl(blockID, blockBlobAsyncClient.getBlobUrl(),
new BlobRange(0, (long) PageBlobClient.PAGE_BYTES))).verifyErrorSatisfies(r -> {
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
});
}*/
assertTrue(e.getStatusCode() == 401);
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
assertTrue(e.getServiceMessage().contains("Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));

});
}

@Test
public void stageBlockFromUrlMin() {
Expand Down Expand Up @@ -2398,7 +2399,7 @@ public void uploadFromUrlMin() {
@Test
public void uploadFromUrlSourceErrorAndStatusCode() {
BlockBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getBlockBlobAsyncClient();

StepVerifier.create(destBlob.uploadFromUrl(blockBlobAsyncClient.getBlobUrl()))
.verifyErrorSatisfies(r -> {
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,20 +531,22 @@ public void uploadPageFromURLMin() {
assertTrue(validateBasicHeaders(response.getHeaders()));
}

/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
@Test
public void uploadPageFromURLSourceErrorAndStatusCode() {
PageBlobClient destBlob = cc.getBlobClient(generateBlobName()).getPageBlobClient();

destBlob.createIfNotExists(Constants.KB);
PageRange pageRange = new PageRange().setStart(0).setEnd(PageBlobClient.PAGE_BYTES - 1);

BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.uploadPagesFromUrl(pageRange, bc.getBlobUrl(), null));

assertTrue(e.getStatusCode() == 409);
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
}*/

BlobStorageException e = assertThrows(BlobStorageException.class,
() -> destBlob.uploadPagesFromUrl(pageRange, bc.getBlobUrl(), null));

assertTrue(e.getStatusCode() == 401);
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
assertTrue(e.getServiceMessage().contains("Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));

}

@Test
public void uploadPageFromURLRange() {
Expand Down
Loading
Loading