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

ImportError for 'ImageNotFoundException' from ECR #3933

Closed
mweitzel2005 opened this issue Nov 15, 2023 · 3 comments
Closed

ImportError for 'ImageNotFoundException' from ECR #3933

mweitzel2005 opened this issue Nov 15, 2023 · 3 comments
Labels
guidance Question that needs advice or information. response-requested Waiting on additional information or feedback.

Comments

@mweitzel2005
Copy link

Describe the bug

Calling .describe_image() against an ECR registry works if the Docker Image tag exists but if it doesn't exists an 'ImageNotFoundException' should be handled.

Trying to import 'ImageNotFoundException' from 'botocore.exceptions' leads to an ImportError.

Expected Behavior

'ImageNotFoundException' should be available for import 'botocore.exceptions'.

Current Behavior

Trying to import 'ImageNotFoundException' from 'botocore.exceptions' leads to an ImportError.

Reproduction Steps

Create a Python script with the below and run it:

from botocore.exceptions import ClientError, ImageNotFoundException

Possible Solution

No response

Additional Information/Context

No response

SDK version used

boto3 1.21.28 / botocore 1.24.28

Environment details (OS name and version, etc.)

mac OS Sonoma

@mweitzel2005 mweitzel2005 added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Nov 15, 2023
@nateprewitt
Copy link
Contributor

Hi @mweitzel2005, thanks for reaching out about this. A large amount of boto3 (and botocore) doesn't actually exist as written Python code, it's generated dynamically at runtime from json models (ImageNotFoundException). So while we have base exceptions like ClientError, you'll find that the exceptions.py file in botocore is only a fraction of the exceptions we may raise.

The service specific exceptions like ImageNotFoundException referenced above actually exist on the client itself. So in this case, your code would look something like:

import boto3
ecr_client = boto3.client('ecr', region_name='us-west-2')
try:
    ecr_client.describe_images()
except ecr_client.exceptions.ImageNotFoundException:
    # your exception handling here

You should find all the errors in the documentation (e.g. describe_images) are expressed in the format ECR.Client.exceptions.<ExceptionName>. You can find the full documentation on how these work in our Error handling guide. Please let us know if you have any other questions.

@nateprewitt nateprewitt added response-requested Waiting on additional information or feedback. guidance Question that needs advice or information. and removed bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Nov 15, 2023
@mweitzel2005
Copy link
Author

Thanks for the clarification, that works.

Copy link

⚠️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
guidance Question that needs advice or information. response-requested Waiting on additional information or feedback.
Projects
None yet
Development

No branches or pull requests

2 participants