Repository: apache/arrow
File: cpp/src/arrow/filesystem/azurefs.cc (C++)

Code before:
  std::shared_ptr<UploadState> upload_state_;

  Blobs::CommitBlockListOptions commit_block_list_options_;
};

bool IsDfsEmulator(const AzureOptions& options) {
  return options.dfs_storage_authority != ".dfs.core.windows.net";
}

}  // namespace

// -----------------------------------------------------------------------
// internal implementation

namespace internal {

Result<HNSSupport> CheckIfHierarchicalNamespaceIsEnabled(
    const DataLake::DataLakeFileSystemClient& adlfs_client, const AzureOptions& options) {
  try {
    auto directory_client = adlfs_client.GetDirectoryClient("");
    // GetAccessControlList will fail on storage accounts
    // without hierarchical namespace enabled.
    directory_client.GetAccessControlList();
    return HNSSupport::kEnabled;
  } catch (std::out_of_range& exception) {
    ARROW_UNUSED(exception);
    // Azurite issue detected.
    DCHECK(IsDfsEmulator(options));
    return HNSSupport::kDisabled;
  } catch (const Core::RequestFailedException& exception) {
    // Flat namespace storage accounts with "soft delete" enabled return
    //
    //   "Conflict - This endpoint does not support BlobStorageEvents
    //   or SoftDelete. [...]" [1],
    //
    // otherwise it returns:
    //
    //   "BadRequest - This operation is only supported on a hierarchical namespace
    //   account."
    //
    // [1]:
    // https://learn.microsoft.com/en-us/answers/questions/1069779/this-endpoint-does-not-support-blobstorageevents-o
    switch (exception.StatusCode) {
      case Http::HttpStatusCode::BadRequest:
      case Http::HttpStatusCode::Conflict:
        return HNSSupport::kDisabled;
      case Http::HttpStatusCode::NotFound:
        if (IsDfsEmulator(options)) {
          return HNSSupport::kDisabled;
        }
        // Did we get an error because of the container not existing?

Review comment (suggestion):
I think we can just remove the variable name?
```suggestion
} catch (const std::out_of_range&) {
```

Code after:
  std::shared_ptr<UploadState> upload_state_;

  Blobs::CommitBlockListOptions commit_block_list_options_;
};

bool IsDfsEmulator(const AzureOptions& options) {
  return options.dfs_storage_authority != ".dfs.core.windows.net";
}

}  // namespace

// -----------------------------------------------------------------------
// internal implementation

namespace internal {

Result<HNSSupport> CheckIfHierarchicalNamespaceIsEnabled(
    const DataLake::DataLakeFileSystemClient& adlfs_client, const AzureOptions& options) {
  try {
    auto directory_client = adlfs_client.GetDirectoryClient("");
    // GetAccessControlList will fail on storage accounts
    // without hierarchical namespace enabled.
    directory_client.GetAccessControlList();
    return HNSSupport::kEnabled;
  } catch (const std::out_of_range&) {
    // Azurite issue detected.
    DCHECK(IsDfsEmulator(options));
    return HNSSupport::kDisabled;
  } catch (const Core::RequestFailedException& exception) {
    // Flat namespace storage accounts with "soft delete" enabled return
    //
    //   "Conflict - This endpoint does not support BlobStorageEvents
    //   or SoftDelete. [...]" [1],
    //
    // otherwise it returns:
    //
    //   "BadRequest - This operation is only supported on a hierarchical namespace
    //   account."
    //
    // [1]:
    // https://learn.microsoft.com/en-us/answers/questions/1069779/this-endpoint-does-not-support-blobstorageevents-o
    switch (exception.StatusCode) {
      case Http::HttpStatusCode::BadRequest:
      case Http::HttpStatusCode::Conflict:
        return HNSSupport::kDisabled;
      case Http::HttpStatusCode::NotFound:
        if (IsDfsEmulator(options)) {
          return HNSSupport::kDisabled;
        }
        // Did we get an error because of the container not existing?
        if (IsContainerNotFound(exception)) {