getmoto / moto

A library that allows you to easily mock out tests based on AWS infrastructure.
http://docs.getmoto.org/en/latest/
Apache License 2.0
7.49k stars 2k forks source link

SQS: get_queue_by_name does not raise QueueDoesNotExist exception when queue does not exist #7827

Open tl24 opened 5 days ago

tl24 commented 5 days ago

With botocore 1.34.17, attempting to load or get a non-existent SQS queue would raise a sqs.meta.client.exceptions.QueueDoesNotExist exception. With newer versions of the boto package, this exception is no longer raised when using moto and the more general ClientError exception is raised instead.

Versions:

Working versions:

I am using moto mocks

It appears that newer versions of boto do not contain fully qualified names like "AWS.SimpleQueueService.NonExistentQueue" in it's exception map. In newer versions of boto, the QueryErrorCode property is set to "QueueDoesNotExist" when calling real AWS while the ErrorCode is still "AWS.SimpleQueueService.NonExistentQueue". The QueryErrorCode takes precedence over ErrorCode when mapping exceptions per this code in botocore.client, and moto is not setting QueryErrorCode, only ErrorCode

       # botocore.client line 1015
        if http.status_code >= 300:
            error_info = parsed_response.get("Error", {})
            error_code = error_info.get("QueryErrorCode") or error_info.get(
                "Code"
            )
            error_class = self.exceptions.from_code(error_code)
            raise error_class(parsed_response, operation_name)
        else:
            return parsed_response

Steps to reproduce

from moto import mock_aws
import pytest

@mock_aws
def test_queue_not_exists_exception():
    from boto3 import resource

    sqs = resource("sqs")
    with pytest.raises(sqs.meta.client.exceptions.QueueDoesNotExist):
        sqs.get_queue_by_name(QueueName="doesnotexist")
tl24 commented 5 days ago

image image