azure-sdk-for-go icon indicating copy to clipboard operation
azure-sdk-for-go copied to clipboard

Unable to get azblob.StorageError for block blob operations

Open deiter opened this issue 3 years ago • 4 comments

Unable to get azblob.StorageError for block blob operations

Steps to reproduce

  • Download the latest versions of github.com/Azure/azure-sdk-for-go
  • Run simple block blob client and try to get properties for non-existing block blob:
import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
...
serviceClient, err := azblob.NewServiceClientWithSharedKey(primaryEndpoint, sharedKeyCredential, nil)
containerClient := serviceClient.NewContainerClient(containerName)
blobClient := containerClient.NewBlockBlobClient(blobName)
properties, err := blockBlob.GetProperties(ctx, nil)
log.Printf("error is %+v: %+v", reflect.TypeOf(err), err)
storageError := azblob.StorageError{}
log.Printf("error is azblob.StorageError: %+v", errors.As(err, &storageError))

Expected results

error is *azblob.StorageError: ....
error is azblob.StorageError: true

Actual results: azblob.InternalError

error is *azblob.InternalError: ===== RESPONSE ERROR (ErrorCode=BlobNotFound) =====
Description=, Details: (none)
error is azblob.StorageError: false

And I didn't find a way to get the original error code - azblob.StorageError / ErrorCode

Thank you!

deiter avatar Jan 10 '22 01:01 deiter

Related issue: https://github.com/Azure/azure-storage-blob-go/issues/58

deiter avatar Jan 10 '22 02:01 deiter

@zezha-msft could you kindly have someone look into this

amishra-dev avatar Jan 25 '22 18:01 amishra-dev

@mohsha-msft I believe a relevant change just happened but it's not released yet, does it address this issue?

zezha-msft avatar Jan 25 '22 20:01 zezha-msft

@mohsha-msft I believe a relevant change just happened but it's not released yet, does it address this issue?

Could you provide a way how to access this StorageError? I'm having the same issue while using 0.4.1 which is released in May.

kaancfidan avatar Jun 23 '22 16:06 kaancfidan

Hi @deiter! Azure Core introduced https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/azcore/errors.go#L14 which can be cast using:

var responseErr *azcore.ResponseError
errors.As(err, &responseErr)

this will be available in the next release.

tasherif-msft avatar Sep 06 '22 15:09 tasherif-msft

The usage of *azcore.ResponseError has been released in [email protected].

jhendrixMSFT avatar Sep 29 '22 21:09 jhendrixMSFT