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

Inconsistent error codes when resources do not exist #1057

Closed
boompig opened this issue Apr 11, 2017 · 2 comments
Closed

Inconsistent error codes when resources do not exist #1057

boompig opened this issue Apr 11, 2017 · 2 comments
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.

Comments

@boompig
Copy link

boompig commented Apr 11, 2017

Sample code:

from aws_utils import make_session

from botocore.exceptions import ClientError
session = make_session()

cf = session.resource("cloudformation")
s3 = session.resource("s3")
iam = session.resource("iam")
ec2 = session.resource("ec2")

bucket = s3.Bucket("foo")
instance = ec2.Instance("i-00135460c82faa880")
role = iam.Role("foo")
stack = cf.Stack("foo")

for resource in [bucket, instance, role, stack]:
    print(type(resource))
    try:
        resource.load()
    except ClientError as e:
        print(e.response["Error"])

Output:

<class 'boto3.resources.factory.s3.Bucket'>
{'Message': 'NotFound', 'Code': '404'}
<class 'boto3.resources.factory.ec2.Instance'>
{'Message': "The instance ID 'i-00135460c82faa880' does not exist", 'Code': 'InvalidInstanceID.NotFound'}
<class 'boto3.resources.factory.iam.Role'>
{'Message': 'Role not found for foo', 'Code': 'NoSuchEntity', 'Type': 'Sender'}
<class 'boto3.resources.factory.cloudformation.Stack'>
{'Message': 'Stack with id foo does not exist', 'Code': 'ValidationError', 'Type': 'Sender'}

There should be some consistency in these cases, since they're basically the same operation and failure. NoSuchEntity seems like the reasonable return code.

@boompig
Copy link
Author

boompig commented Apr 11, 2017

And for a few services that don't have the Resource semantics and only support clients:

def test_clients():
    l_cli = session.client("lambda")
    try:
        l_cli.get_function(FunctionName="foo")
    except ClientError as e:
        print(e.response["Error"])
    k_cli = session.client("kinesis")
    try:
        # closest I could find to `get_stream`, which doesn't exist
        k_cli.describe_stream(StreamName="foo")
    except ClientError as e:
        print(e.response["Error"])

test_clients()

Output:

{'Message': u'Function not found: arn:aws:lambda:us-west-1:xxxxxxxxxxx:function:foo', 'Code': 'ResourceNotFoundException'}
{'Message': u'Stream foo under account xxxxxxxxxxx not found.', 'Code': u'ResourceNotFoundException'}

This is PHP-level inconsistency.

@JordonPhillips JordonPhillips added guidance Question that needs advice or information. closing-soon This issue will automatically close in 4 days unless further comments are made. labels Apr 12, 2017
@JordonPhillips
Copy link
Contributor

Unfortunately there's nothing we can do about that since it's a service-side issue, and changing it now would be backwards-incompatible besides. FWIW I agree that it's confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants