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

S3 storage backend's size method raise botocore.exceptions.ClientError instead of FileNotFoundError #1022

Closed
nl-emmanuellodovice opened this issue Jun 9, 2021 · 2 comments

Comments

@nl-emmanuellodovice
Copy link

When you call default_storage.size(path_that_does_not_exists) with S3Boto3Storage as the default storage backend, it will raise botocore.exceptions.ClientError instead of FileNotFoundError.

@jschneier
Copy link
Owner

Let's say I wrap this but now some other client error is encountered, what should happen?

@nl-emmanuellodovice
Copy link
Author

Thanks for checking this. I am not a boto expert but I was thinking may be we can check the response for the exception and see if the code is 404 and only then raise the FileNotFoundError.

Something like

try:
    size = default_storage.size("does_not_exists.file")
except ClientError as e:
    if e.response.get("Error", {}).get("Code", None) == '404':
        raise FileNotFoundError("does_not_exists.file does not exist.")
    else:
        raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants