From 112fef4f47a3e12571f6c287497c481b1190f04a Mon Sep 17 00:00:00 2001 From: Patrick Hagan <56281590+glerb@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:47:31 -0800 Subject: [PATCH 1/3] Add raise from ClientError S3UploadFailedError currently replaces ClientError, but does not include a "from ClientError" clause to allow the original ClientError information to be accessed by other packages. Adding this clause will allow access to ClientError elements via `e.__cause__` --- boto3/s3/transfer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boto3/s3/transfer.py b/boto3/s3/transfer.py index 73a3388b46..486e138c62 100644 --- a/boto3/s3/transfer.py +++ b/boto3/s3/transfer.py @@ -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 From 07aab7db756e289591472896cdb9f312988c6243 Mon Sep 17 00:00:00 2001 From: Patrick Hagan <56281590+glerb@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:19:10 -0800 Subject: [PATCH 2/3] Docs update --- docs/source/guide/error-handling.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/source/guide/error-handling.rst b/docs/source/guide/error-handling.rst index bd83d7cc29..42f3062629 100644 --- a/docs/source/guide/error-handling.rst +++ b/docs/source/guide/error-handling.rst @@ -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__.ClientError + 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 From 4ebf3984c18cf98eed2c92c1b90d3d1911055936 Mon Sep 17 00:00:00 2001 From: Patrick Hagan <56281590+glerb@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:34:51 -0800 Subject: [PATCH 3/3] Small typo --- docs/source/guide/error-handling.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/guide/error-handling.rst b/docs/source/guide/error-handling.rst index 42f3062629..bcf40e1f9f 100644 --- a/docs/source/guide/error-handling.rst +++ b/docs/source/guide/error-handling.rst @@ -205,7 +205,7 @@ Using Amazon Kinesis as an example service, you can use Boto3 to catch the excep .. code-block:: python except boto3.exceptions.S3UploadFailedError as error: - _clientError = error.__cause__.ClientError + _clientError = error.__cause__ if _clientError.response['Error']['Code'] == 'InvalidRequest': logger.warn(f"There was an error when attempting to upload: {_clientError.response['Error']['Message']}")