2323try :
2424 import boto3
2525 import boto3 .session
26+ from boto3 .exceptions import S3UploadFailedError
2627 from botocore .exceptions import ClientError
2728
2829 boto3_import_error = None
@@ -254,7 +255,7 @@ def copy_from_local(uri_or_path, local_path):
254255 Raises
255256 ------
256257 RuntimeError
257- If there was a problem when removing .
258+ If there was a problem when copying .
258259 """
259260 create_resource (uri_or_path ).copy_from_local (local_path )
260261
@@ -272,7 +273,7 @@ def copy_to_local(uri_or_path, local_path):
272273 Raises
273274 ------
274275 RuntimeError
275- If there was a problem when removing .
276+ If there was a problem when copying .
276277 """
277278 create_resource (uri_or_path ).copy_to_local (local_path )
278279
@@ -668,29 +669,22 @@ def remove(self):
668669 )
669670
670671 def copy_from_local (self , local_path ):
671- response = self .s3_client .Bucket (self .uri_info .netloc ).upload_file (
672- local_path , self .uri_info .path [1 :]
673- )
674- status_code = response ["ResponseMetadata" ]["HTTPStatusCode" ]
675- copy_ok = 200 <= status_code <= 299
676- if not copy_ok :
677- raise RuntimeError (
678- f"S3 copy_from_local failed { self .uri } with code { status_code } : "
679- + json .dumps (response )
672+ try :
673+ self .s3_client .Bucket (self .uri_info .netloc ).upload_file (
674+ local_path , self .uri_info .path [1 :]
680675 )
676+ # normalize the raised exception
677+ except S3UploadFailedError as exc :
678+ raise RuntimeError (f"S3 copy_from_local failed { self .uri } " ) from exc
681679
682680 def copy_to_local (self , local_path ):
683- response = self .s3_client .Bucket (self .uri_info .netloc ).download_file (
684- local_path , self .uri_info .path [1 :]
685- )
686- status_code = response ["ResponseMetadata" ]["HTTPStatusCode" ]
687- copy_ok = 200 <= status_code <= 299
688- if not copy_ok :
689- raise RuntimeError (
690- f"S3 download failed { self .uri } with code { status_code } : "
691- + json .dumps (response )
681+ try :
682+ self .s3_client .Bucket (self .uri_info .netloc ).download_file (
683+ self .uri_info .path [1 :], local_path
692684 )
693- return copy_ok
685+ # normalize the raised exception
686+ except S3UploadFailedError as exc :
687+ raise RuntimeError (f"S3 download failed { self .uri } " ) from exc
694688
695689 def list_dir (self ):
696690 # Add an extra slash to the path to treat it as a folder
0 commit comments