Skip to content
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

azblob: StorageError might be empty for the current implement UnmarshalXML in the azurite environment. #16542

Closed
Leavrth opened this issue Dec 9, 2021 · 3 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Storage Storage Service (Queues, Blobs, Files)

Comments

@Leavrth
Copy link

Leavrth commented Dec 9, 2021

Bug Report

  • import path of package in question: import github.com/Azure/azure-sdk-for-go/sdk/storage/azblob
  • SDK version master
  • output of go version
go version
go version go1.16.7 darwin/amd64
  • What happened?
    This is my code, and the azurite is running.
import (
	"context"
	"fmt"

	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
	connStr := "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
	service, err := azblob.NewServiceClientFromConnectionString(connStr, nil)
	if err != nil {
		fmt.Printf("err1 %s", err.Error())
		return
	}
	ctx := context.Background()
	client := service.NewContainerClient("test254").NewBlockBlobClient("tt2")
	_, err = client.Download(ctx, nil)
	if err != nil {
		fmt.Printf("err %s\n", err.Error())
		return
	}
	return
}

In fact, container test254 is not exsit in the Azurite. So we will see the error print in the terminal.
But terminal show this,

err ===== RESPONSE ERROR (ErrorCode=
  ) =====
Description=
, Details: 
   : 
  
  • What did you expect or want to happen?
    Instead, it should show this,
err ===== RESPONSE ERROR (ErrorCode=ContainerNotFound) =====
Description=The specified container does not exist.
RequestId:e10eeea8-73cf-4ec9-b717-ea1f4ee47a8b
Time:2021-12-09T05:49:23.887Z, Details: 
   : 

I insert fmt.Printf to print the info into these positions:

// UnmarshalAsXML calls xml.Unmarshal() to unmarshal the received payload into the value pointed to by v.
func UnmarshalAsXML(resp *http.Response, v interface{}) error {
payload, err := Payload(resp)
if err != nil {
return err
}
// TODO: verify early exit is correct
if len(payload) == 0 {
return nil
}
err = removeBOM(resp)
if err != nil {
return err
}
err = xml.Unmarshal(payload, v)
if err != nil {
err = fmt.Errorf("unmarshalling type %T: %s", v, err)
}
return err
}

print the payload:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Error>
  <Code>ContainerNotFound</Code>
  <Message>The specified container does not exist.
RequestId:e10eeea8-73cf-4ec9-b717-ea1f4ee47a8b
Time:2021-12-09T05:49:23.887Z</Message>
</Error>

// UnmarshalXML performs custom unmarshalling of XML-formatted Azure storage request errors.
//nolint
func (e *StorageError) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
tokName := ""
var t xml.Token
for t, err = d.Token(); err == nil; t, err = d.Token() {
switch tt := t.(type) {
case xml.StartElement:
tokName = tt.Name.Local
case xml.CharData:
switch tokName {
case "Message":
e.description = string(tt)
default:
if e.details == nil {
e.details = map[string]string{}
}
e.details[tokName] = string(tt)
}
}
}
return nil
}

insert after L195 to print token name fmt.Printf("token name is %s\n", tokName)
insert after L199 to print description fmt.Printf("description is %s\n", e.description)
insert after L204 to print detail fmt.Printf("detail[%s]=%s\n", tokName, string(tt))

detail[]=
  
token name is Code
detail[Code]=ContainerNotFound
detail[Code]=
  
token name is Message
description is The specified container does not exist.
RequestId:e8be3a84-f877-4b62-a7aa-7aaa8d44ccb4
Time:2021-12-09T06:19:16.483Z
description is 

I found each value are overwrite with empty value.

after insert case xml.EndElement: to reset tokenName, everything seems ok.

// UnmarshalXML performs custom unmarshalling of XML-formatted Azure storage request errors.
//nolint
func (e *StorageError) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
	tokName := ""
	var t xml.Token
	for t, err = d.Token(); err == nil; t, err = d.Token() {
		switch tt := t.(type) {
		case xml.StartElement:
			tokName = tt.Name.Local
		case xml.CharData:
			switch tokName {
			case "Message":
				e.description = string(tt)
			default:
				if e.details == nil {
					e.details = map[string]string{}
				}
				e.details[tokName] = string(tt)
			}
		case xml.EndElement:
			tokName = ""
		}
	}

	return nil
}

  • How can we reproduce it?
    run the Azurite, and run my code above.
  • Anything we should know about your environment.
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 9, 2021
@RickWinter RickWinter added bug This issue requires a change to an existing behavior in the product in order to be resolved. Storage Storage Service (Queues, Blobs, Files) labels Dec 9, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Dec 9, 2021
@RickWinter RickWinter added Client This issue points to a problem in the data-plane of the library. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 9, 2021
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Dec 9, 2021
@mohsha-msft
Copy link
Contributor

Hey @Leavrth ,

Thanks for reporting the issue. @johnstairs has fixed the issue and I've merged it in dev-azblob branch.
Can you please try go get github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@dev-azblob.

Please reach out if the issue persists.

@mohsha-msft
Copy link
Contributor

Once we do the next release of azblob, we'll include this change and close this issue.

@mohsha-msft
Copy link
Contributor

Fixed in sdk/storage/azblob/v0.3.0

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

4 participants