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

SQS error code not match #5090

Closed
chuzui opened this issue Nov 30, 2023 · 3 comments · Fixed by #5101
Closed

SQS error code not match #5090

chuzui opened this issue Nov 30, 2023 · 3 comments · Fixed by #5101
Assignees
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue

Comments

@chuzui
Copy link

chuzui commented Nov 30, 2023

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

@chuzui chuzui added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2023
@RanVaknin RanVaknin self-assigned this Nov 30, 2023
@RanVaknin RanVaknin added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2023
@RanVaknin
Copy link
Contributor

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~

@isaiahvita isaiahvita assigned isaiahvita and unassigned RanVaknin Dec 1, 2023
@isaiahvita
Copy link
Contributor

isaiahvita commented Dec 7, 2023

@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/

Copy link

github-actions bot commented Dec 8, 2023

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants