diff --git a/sdk/core/azure-core/inc/azure/core/azure_assert.hpp b/sdk/core/azure-core/inc/azure/core/azure_assert.hpp index d16ee8e42..fcd9bf5e1 100644 --- a/sdk/core/azure-core/inc/azure/core/azure_assert.hpp +++ b/sdk/core/azure-core/inc/azure/core/azure_assert.hpp @@ -52,5 +52,5 @@ [[noreturn]] void AzureNoReturnPath(std::string const& msg); #define AZURE_ASSERT_FALSE(exp) AZURE_ASSERT(!(exp)) -#define AZURE_UNREACHABLE_CODE AzureNoReturnPath("unreachable code!") -#define AZURE_NOT_IMPLEMENTED AzureNoReturnPath("not implemented code!") +#define AZURE_UNREACHABLE_CODE() AzureNoReturnPath("unreachable code!") +#define AZURE_NOT_IMPLEMENTED() AzureNoReturnPath("not implemented code!") diff --git a/sdk/core/azure-core/inc/azure/core/etag.hpp b/sdk/core/azure-core/inc/azure/core/etag.hpp index 2ddf4fa6a..d4de57880 100644 --- a/sdk/core/azure-core/inc/azure/core/etag.hpp +++ b/sdk/core/azure-core/inc/azure/core/etag.hpp @@ -114,7 +114,7 @@ public: break; } // Unknown comparison - AZURE_UNREACHABLE_CODE; + AZURE_UNREACHABLE_CODE(); } /** diff --git a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_responses.hpp b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_responses.hpp index f21a589db..00bcc02c6 100644 --- a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_responses.hpp +++ b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_responses.hpp @@ -187,11 +187,7 @@ namespace Azure { namespace Storage { ~StartBlobCopyOperation() override {} private: - std::string GetResumeToken() const override - { - // Not supported - std::abort(); - } + std::string GetResumeToken() const override { AZURE_NOT_IMPLEMENTED(); } std::unique_ptr PollInternal( const Azure::Core::Context& context) override; diff --git a/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp b/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp index b9fa63ada..1e38506d5 100644 --- a/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp +++ b/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp @@ -3,6 +3,7 @@ #include "azure/storage/blobs/blob_lease_client.hpp" +#include #include namespace Azure { namespace Storage { namespace Blobs { @@ -52,12 +53,16 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince; protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince; - if (options.AccessConditions.IfMatch.HasValue() - || options.AccessConditions.IfNoneMatch.HasValue() - || options.AccessConditions.TagConditions.HasValue()) - { - std::abort(); - } + AZURE_ASSERT_MSG( + !options.AccessConditions.IfMatch.HasValue(), + "Blob container lease doesn't support If-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.IfNoneMatch.HasValue(), + "Blob container lease doesn't support If-None-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.TagConditions.HasValue(), + "Blob container lease doesn't support tag condition"); + auto response = _detail::BlobRestClient::BlobContainer::AcquireLease( *(m_blobContainerClient.Value().m_pipeline), m_blobContainerClient.Value().m_blobContainerUrl, @@ -74,7 +79,7 @@ namespace Azure { namespace Storage { namespace Blobs { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -113,12 +118,15 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince; protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince; - if (options.AccessConditions.IfMatch.HasValue() - || options.AccessConditions.IfNoneMatch.HasValue() - || options.AccessConditions.TagConditions.HasValue()) - { - std::abort(); - } + AZURE_ASSERT_MSG( + !options.AccessConditions.IfMatch.HasValue(), + "Blob container lease doesn't support If-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.IfNoneMatch.HasValue(), + "Blob container lease doesn't support If-None-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.TagConditions.HasValue(), + "Blob container lease doesn't support tag condition"); auto response = _detail::BlobRestClient::BlobContainer::RenewLease( *(m_blobContainerClient.Value().m_pipeline), @@ -136,7 +144,7 @@ namespace Azure { namespace Storage { namespace Blobs { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -174,12 +182,15 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince; protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince; - if (options.AccessConditions.IfMatch.HasValue() - || options.AccessConditions.IfNoneMatch.HasValue() - || options.AccessConditions.TagConditions.HasValue()) - { - std::abort(); - } + AZURE_ASSERT_MSG( + !options.AccessConditions.IfMatch.HasValue(), + "Blob container lease doesn't support If-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.IfNoneMatch.HasValue(), + "Blob container lease doesn't support If-None-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.TagConditions.HasValue(), + "Blob container lease doesn't support tag condition"); auto response = _detail::BlobRestClient::BlobContainer::ReleaseLease( *(m_blobContainerClient.Value().m_pipeline), @@ -196,7 +207,7 @@ namespace Azure { namespace Storage { namespace Blobs { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -243,12 +254,15 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince; protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince; - if (options.AccessConditions.IfMatch.HasValue() - || options.AccessConditions.IfNoneMatch.HasValue() - || options.AccessConditions.TagConditions.HasValue()) - { - std::abort(); - } + AZURE_ASSERT_MSG( + !options.AccessConditions.IfMatch.HasValue(), + "Blob container lease doesn't support If-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.IfNoneMatch.HasValue(), + "Blob container lease doesn't support If-None-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.TagConditions.HasValue(), + "Blob container lease doesn't support tag condition"); auto response = _detail::BlobRestClient::BlobContainer::ChangeLease( *(m_blobContainerClient.Value().m_pipeline), @@ -271,7 +285,7 @@ namespace Azure { namespace Storage { namespace Blobs { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -309,12 +323,15 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince; protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince; - if (options.AccessConditions.IfMatch.HasValue() - || options.AccessConditions.IfNoneMatch.HasValue() - || options.AccessConditions.TagConditions.HasValue()) - { - std::abort(); - } + AZURE_ASSERT_MSG( + !options.AccessConditions.IfMatch.HasValue(), + "Blob container lease doesn't support If-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.IfNoneMatch.HasValue(), + "Blob container lease doesn't support If-None-Match condition"); + AZURE_ASSERT_MSG( + !options.AccessConditions.TagConditions.HasValue(), + "Blob container lease doesn't support tag condition"); auto response = _detail::BlobRestClient::BlobContainer::BreakLease( *(m_blobContainerClient.Value().m_pipeline), @@ -331,7 +348,7 @@ namespace Azure { namespace Storage { namespace Blobs { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } }}} // namespace Azure::Storage::Blobs diff --git a/sdk/storage/azure-storage-blobs/src/blob_responses.cpp b/sdk/storage/azure-storage-blobs/src/blob_responses.cpp index ee8467066..9f59ecc14 100644 --- a/sdk/storage/azure-storage-blobs/src/blob_responses.cpp +++ b/sdk/storage/azure-storage-blobs/src/blob_responses.cpp @@ -103,8 +103,7 @@ namespace Azure { namespace Storage { namespace Blobs { *this = m_pageBlobClient->GetManagedDiskPageRangesDiff( m_previousSnapshotUrl.Value(), m_operationOptions, context); } - // Execution is never expected to reach here - std::abort(); + AZURE_UNREACHABLE_CODE(); } }}} // namespace Azure::Storage::Blobs diff --git a/sdk/storage/azure-storage-common/inc/azure/storage/common/concurrent_transfer.hpp b/sdk/storage/azure-storage-common/inc/azure/storage/common/concurrent_transfer.hpp index 856b0cffa..fdb7f2d9a 100644 --- a/sdk/storage/azure-storage-common/inc/azure/storage/common/concurrent_transfer.hpp +++ b/sdk/storage/azure-storage-common/inc/azure/storage/common/concurrent_transfer.hpp @@ -63,11 +63,6 @@ namespace Azure { namespace Storage { namespace _internal { { handle.get(); } - - if (numWorkingThreads != 0) - { - std::abort(); - } } }}} // namespace Azure::Storage::_internal diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp index bc1b73726..508928703 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp @@ -157,10 +157,11 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { protocolLayerOptions.RetainUncommittedData = options.RetainUncommittedData; protocolLayerOptions.Close = options.Close; protocolLayerOptions.ContentLength = 0; - if (options.ContentHash.HasValue() - && options.ContentHash.Value().Algorithm != HashAlgorithm::Md5) + if (options.ContentHash.HasValue()) { - std::abort(); + AZURE_ASSERT_MSG( + options.ContentHash.Value().Algorithm == HashAlgorithm::Md5, + "This operation only supports MD5 content hash."); } protocolLayerOptions.ContentMd5 = options.ContentHash; protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId; @@ -376,11 +377,10 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { { Blobs::_detail::BlobRestClient::Blob::SetBlobExpiryOptions protocolLayerOptions; protocolLayerOptions.ExpiryOrigin = expiryOrigin; - if (options.ExpiresOn.HasValue() && options.TimeToExpire.HasValue()) - { - // ExpiresOn and TimeToExpire should be mutually exclusive. - std::abort(); - } + AZURE_ASSERT_MSG( + !(options.ExpiresOn.HasValue() && options.TimeToExpire.HasValue()), + "ExpiresOn and TimeToExpire are mutually exclusive"); + if (options.ExpiresOn.HasValue()) { protocolLayerOptions.ExpiryTime diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp index b489f0062..b9737919a 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp @@ -251,10 +251,10 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { { Blobs::SetBlobContainerMetadataOptions blobOptions; blobOptions.AccessConditions.IfModifiedSince = options.AccessConditions.IfModifiedSince; - if (options.AccessConditions.IfUnmodifiedSince.HasValue()) - { - std::abort(); - } + AZURE_ASSERT_MSG( + !options.AccessConditions.IfUnmodifiedSince.HasValue(), + "This operation doesn't support If-Unmodified-Since condition"); + auto result = m_blobContainerClient.SetMetadata(std::move(metadata), blobOptions, context); Models::SetFileSystemMetadataResult ret; ret.ETag = std::move(result.Value.ETag); diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_responses.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_responses.cpp index 0433b12b8..b1a1a41b8 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_responses.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_responses.cpp @@ -111,8 +111,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { *this = m_dataLakePathClient->RemoveAccessControlListRecursive( m_acls, m_operationOptions, context); } - // Execution is never expected to reach here - std::abort(); + AZURE_UNREACHABLE_CODE(); } }}}} // namespace Azure::Storage::Files::DataLake diff --git a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_responses.hpp b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_responses.hpp index 34eb17ff9..301b7f3c5 100644 --- a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_responses.hpp +++ b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_responses.hpp @@ -226,11 +226,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { ~StartFileCopyOperation() override {} private: - std::string GetResumeToken() const override - { - // Not supported - std::abort(); - } + std::string GetResumeToken() const override { AZURE_NOT_IMPLEMENTED(); } std::unique_ptr PollInternal( const Azure::Core::Context& context) override; diff --git a/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp b/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp index 7d995e4de..4b24e1ff7 100644 --- a/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp +++ b/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp @@ -166,10 +166,9 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } if (!options.HttpHeaders.ContentHash.Value.empty()) { - if (options.HttpHeaders.ContentHash.Algorithm != HashAlgorithm::Md5) - { - std::abort(); - } + AZURE_ASSERT_MSG( + options.HttpHeaders.ContentHash.Algorithm == HashAlgorithm::Md5, + "This operation only supports MD5 content hash"); protocolLayerOptions.ContentMd5 = options.HttpHeaders.ContentHash; } protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId; @@ -241,14 +240,13 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } if (options.RangeHashAlgorithm.HasValue()) { + AZURE_ASSERT_MSG( + options.RangeHashAlgorithm.Value() == HashAlgorithm::Md5, + "This operation only supports MD5 content hash"); if (options.RangeHashAlgorithm.Value() == HashAlgorithm::Md5) { protocolLayerOptions.GetRangeContentMd5 = true; } - else - { - std::abort(); - } } protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId; @@ -353,9 +351,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } else { - // FilePermission or FilePermissionKey must be set if FilePermissionCopyMode is set to - // PermissionCopyModeType::Override. - std::abort(); + AZURE_ASSERT_MSG(false, "Either FilePermission or FilePermissionKey must be set"); } } } @@ -490,10 +486,11 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { protocolLayerOptions.ContentLength = content.Length(); protocolLayerOptions.XMsRange = std::string("bytes=") + std::to_string(offset) + std::string("-") + std::to_string(offset + content.Length() - 1); - if (options.TransactionalContentHash.HasValue() - && options.TransactionalContentHash.Value().Algorithm != HashAlgorithm::Md5) + if (options.TransactionalContentHash.HasValue()) { - std::abort(); + AZURE_ASSERT_MSG( + options.TransactionalContentHash.Value().Algorithm == HashAlgorithm::Md5, + "This operation only supports MD5 content hash"); } protocolLayerOptions.ContentMd5 = options.TransactionalContentHash; protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId; @@ -930,10 +927,9 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } if (!options.HttpHeaders.ContentHash.Value.empty()) { - if (options.HttpHeaders.ContentHash.Algorithm != HashAlgorithm::Md5) - { - std::abort(); - } + AZURE_ASSERT_MSG( + options.HttpHeaders.ContentHash.Algorithm == HashAlgorithm::Md5, + "This operation only supports MD5 content hash"); protocolLayerOptions.ContentMd5 = options.HttpHeaders.ContentHash; } protocolLayerOptions.Metadata = options.Metadata; @@ -1033,10 +1029,9 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } if (!options.HttpHeaders.ContentHash.Value.empty()) { - if (options.HttpHeaders.ContentHash.Algorithm != HashAlgorithm::Md5) - { - std::abort(); - } + AZURE_ASSERT_MSG( + options.HttpHeaders.ContentHash.Algorithm == HashAlgorithm::Md5, + "This operation only supports MD5 content hash"); protocolLayerOptions.ContentMd5 = options.HttpHeaders.ContentHash; } protocolLayerOptions.Metadata = options.Metadata; @@ -1078,11 +1073,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { const UploadFileRangeFromUriOptions& options, const Azure::Core::Context& context) const { - if (!sourceRange.Length.HasValue()) - { - // sourceRange must have length to perform this operation. - std::abort(); - } + AZURE_ASSERT_MSG(sourceRange.Length.HasValue(), "Source length cannot be null"); int64_t rangeLength = sourceRange.Length.Value(); auto protocolLayerOptions = _detail::ShareRestClient::File::UploadRangeFromUrlOptions(); @@ -1091,26 +1082,27 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { protocolLayerOptions.ContentLength = 0; protocolLayerOptions.CopySource = sourceUri; protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId; - if (options.TransactionalContentHash.HasValue() - && options.TransactionalContentHash.Value().Algorithm == HashAlgorithm::Md5) + if (options.TransactionalContentHash.HasValue()) { - // SourceContentHash now only supports Crc64 hash algorithm. - std::abort(); + AZURE_ASSERT_MSG( + options.TransactionalContentHash.Value().Algorithm == HashAlgorithm::Crc64, + "This operation only supports CRC64 content hash"); } protocolLayerOptions.SourceContentCrc64 = options.TransactionalContentHash; - if (options.SourceAccessCondition.IfMatchContentHash.HasValue() - && options.SourceAccessCondition.IfMatchContentHash.Value().Algorithm == HashAlgorithm::Md5) + if (options.SourceAccessCondition.IfMatchContentHash.HasValue()) { - // IfMatchContentHash now only supports Crc64 hash algorithm. - std::abort(); + AZURE_ASSERT_MSG( + options.SourceAccessCondition.IfMatchContentHash.Value().Algorithm + == HashAlgorithm::Crc64, + "This operation only supports CRC64 Source-If-Match condition"); } protocolLayerOptions.SourceIfMatchCrc64 = options.SourceAccessCondition.IfMatchContentHash; - if (options.SourceAccessCondition.IfNoneMatchContentHash.HasValue() - && options.SourceAccessCondition.IfNoneMatchContentHash.Value().Algorithm - == HashAlgorithm::Md5) + if (options.SourceAccessCondition.IfNoneMatchContentHash.HasValue()) { - // IfNoneMatchContentHash now only supports Crc64 hash algorithm. - std::abort(); + AZURE_ASSERT_MSG( + options.SourceAccessCondition.IfNoneMatchContentHash.Value().Algorithm + == HashAlgorithm::Crc64, + "This operation only supports CRC64 Source-If-None-Match condition"); } protocolLayerOptions.SourceIfNoneMatchCrc64 = options.SourceAccessCondition.IfNoneMatchContentHash; diff --git a/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp b/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp index 2ad1c3ef7..3863c5793 100644 --- a/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp +++ b/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp @@ -62,7 +62,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -73,8 +73,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { (void)options; if (m_fileClient.HasValue()) { - // Renew only support share level lease. - std::abort(); + AZURE_ASSERT_MSG(false, "Share lease doesn't support renew"); + AZURE_NOT_IMPLEMENTED(); } else if (m_shareClient.HasValue()) { @@ -97,7 +97,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -144,7 +144,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -206,7 +206,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } @@ -251,7 +251,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } else { - std::abort(); + AZURE_UNREACHABLE_CODE(); } } }}}} // namespace Azure::Storage::Files::Shares