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

Make ClientError accessible from S3UploadFailedError #4346

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boto3/s3/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def upload_file(
"Failed to upload {} to {}: {}".format(
filename, '/'.join([bucket, key]), e
)
)
) from ClientError

def download_file(
self, bucket, key, filename, extra_args=None, callback=None
Expand Down
11 changes: 11 additions & 0 deletions docs/source/guide/error-handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ Using Amazon Kinesis as an example service, you can use Boto3 to catch the excep

The Boto3 ``standard`` retry mode will catch throttling errors and exceptions, and will back off and retry them for you.

.. note::

The low-level clients for a few AWS services, such as S3, do not return service errors in a ``ClientError`` object. However, the ``ClientError`` may be accessible via the ``__cause__`` attribute of the overlying error:
.. code-block:: python

except boto3.exceptions.S3UploadFailedError as error:
_clientError = error.__cause__
if _clientError.response['Error']['Code'] == 'InvalidRequest':
logger.warn(f"There was an error when attempting to upload: {_clientError.response['Error']['Message']}")


Additionally, you can also access some of the dynamic service-side exceptions from the client’s exception property. Using the previous example, you would need to modify only the ``except`` clause.

.. code-block:: python
Expand Down
Loading