-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 handling in S3: old boto3.exceptions.S3UploadFailedError replaces modern botocore.exceptions.ClientError #4299
Comments
Hi @glerb, thanks for reaching out. I have used the code that you have provided and I was not able to replicate the errors. For a further look, please provide the full debug logs by adding boto3.set_stream_logger('') to your code and redacting any sensitive information. Also, please let me know the type of file you were uploading, content type, and its size. Thanks. |
@adev-code the error I used above was just an example intentionally designed to create an error (in this case, trying to upload a file to a bucket with Object Lock enabled, but without specifying a checksum algorithm). The specific error is almost certainly irrelevant. You can probably cause an error any way you want. The issue I'm flagging is the handling of errors generally. |
Hi @glerb, thanks for the update. Boto3 is throwing a ClientError as documented, and it's throwing the S3UploadFailedError to provide additional information. This behavior is expected; please let me know if you have any follow-up questions. Thanks! |
It isn't, though. Or rather, the https://github.com/boto/boto3/blob/develop/boto3/s3/transfer.py#L377 Because |
Hi @glerb, the error being raised is what many users expect currently although I understand the confusion caused by the asymmetry. The underlying issue is Changing the more specialized exception to a We can also look at making this caveat clearer in the specific S3transfer operations attached to the S3 client so there is less surprise when this get raised. |
Sounds good. That should be mentioned prominently in the docs, though, preferably in the form of an example. That is something the average SDK user is not going to be able to figure out on their own. Another way of doing it without any changes being necessary in Would another solution be setting |
That will unfortunately have the same breaking behaviors as anything currently catching ClientError before this will potentially start handling it differently. ClientError (despite it's naming) is specifically for errors returned from a service and while it's coming from a
Yep, that's definitely an option, but I agree it's not something all Python devs are going to be comfortable with. The We'll work on drafting a PR for that up and revisit this once it's ready for review. |
Something to get you started: #4346 |
Describe the bug
The
boto3
S3 client does not process S3 service errors like every other service client. It throws a different error than other service clients do when encountering AWS service errors.This is a bump of #1986 from 2019(!).
Regression Issue
Expected Behavior
A ClientError object should be returned to an
except ClientError as error:
clause when an S3 service error is returned tobotocore
, per current docs (which apparently haven't changed for years).Current Behavior
The
boto3
client raises a second error,S3UploadFailedError
, from theboto3
exceptions when executingboto3.client('s3').upload_file()
:Reproduction Steps
Possible Solution
The reason this is a "bug" is that there is some "backwards compatibility" error handler in
boto3/s3/transfer.py
that raises the (old?)S3UploadFailedError
when the (modern?)botocore/client.py
raises aClientError
. Thus, the S3 client does not behave as the current error handling instructions suggest, and there is no additional information in any of the documentation about this. Additionally, this old error handler does not return the full response dictionary in a way that is expected by developers catching aClientError
. Instead, the original error is returned as its__str__
/__repr__
by theS3UploadFailedError
. Developers have to go spelunking through the library to discover this.Additional Information/Context
No response
SDK version used
1.35.25
Environment details (OS name and version, etc.)
Linux 5.15.0-202.135.2.el9uek.x86_64 #2 SMP x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: