aws / aws-sdk-go

AWS SDK for the Go programming language.

Home Page:http://aws.amazon.com/sdk-for-go/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SQS error code not match

chuzui opened this issue · comments

Describe the bug

After the #5060, for example, the error code of deleting a non-existent queue is changed from AWS.SimpleQueueService.NonExistentQueue to NonExistentQueue. But the SQS api comes back with AWS.SimpleQueueService.NonExistentQueue in practise and make the error code check unworkable.

aws/aws-sdk-go-v2#2348
aws/aws-sdk#105

Expected Behavior

The error code of deleting a non-existent queue can match sqs.ErrCodeQueueDoesNotExist

Current Behavior

Not match

Reproduction Steps

input := &sqs.DeleteQueueInput{
                 // non-existent queue
		QueueUrl: aws.String(url),
	}

if _, err := s.DeleteQueue(input); err != nil {
	if ae, ok := err.(awserr.Error); ok && ae.Code() == sqs.ErrCodeQueueDoesNotExist {
		return nil
	} else {
		return err
	}
}

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.47.13

Environment details (Version of Go (go version)? OS name and version, etc.)

go1.19.7 linux/amd64

Hi @chuzui ,

Thanks for the message,

I can confirm this behavior. I think the problem is that the Go v1 SDK is drawing the error from the header rather than the body.

As you can see the following response :

-----------------------------------------------------
2023/11/30 13:53:29 DEBUG: Response sqs/SendMessageBatch Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 400 Bad Request
Content-Length: 96
Connection: keep-alive
Content-Type: application/x-amz-json-1.0
Date: Thu, 30 Nov 2023 21:53:29 GMT
X-Amzn-Query-Error: AWS.SimpleQueueService.NonExistentQueue;Sender
X-Amzn-Requestid: REDACTED


-----------------------------------------------------
2023/11/30 13:53:29 {"__type":"com.amazonaws.sqs#QueueDoesNotExist","message":"The specified queue does not exist."}

The SQS response contains both error codes; QueueDoesNotExist in the body, and AWS.SimpleQueueService.NonExistentQueue in the error header. By default the SDK will look in the header first and prioritize the error returned in the header (because HEAD operations do not return a body).

I'm not sure what the fix here should be, but this is working correctly in v2:

func main() {
	ctx := context.Background()
	cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-east-1"), config.WithClientLogMode(aws.LogResponseWithBody))
	if err != nil {
		log.Fatalf("unable to load SDK config, %v", err)
	}

	client := sqs.NewFromConfig(cfg)

	_, err = client.GetQueueUrl(context.TODO(), &sqs.GetQueueUrlInput{
		QueueName: aws.String("fake-foo-queue"),
	})
	if err != nil {
		var e *types.QueueDoesNotExist
		if errors.As(err, &e) {
			fmt.Println("\n we get the expected error")
		} else {
			panic(err)
		}
	}
}
/*

 we get the expected error

*/

We will further look into it.
Thanks,
Ran~

@chuzui thanks for creating the issue. Your worry is valid, and we are actively working on amending back to the older customer experience. And, I will update this thread as we progress.

in the meantime, the deserialized error awserr.Error.Code() (the value received from the service at runtime), will return all the old string values of the error constants (pre 11/8/2023), which you can validate against. see here:
https://github.com/aws/aws-sdk-go/blob/b87529cf2de4aefd7509be28ff294cf2dda46dcd/service/sqs/errors.go

some context around the source of the issue:
#5060
https://aws.amazon.com/about-aws/whats-new/2023/11/amazon-sqs-support-json-protocol/

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.