Skip to content

Commit

Permalink
Fix copy_from_local for AmazonS3Resource filesystems, upload_file doe…
Browse files Browse the repository at this point in the history
…s not return a response but raises an exception in case of error
  • Loading branch information
Thierry RAMORASOAVINA committed Dec 2, 2024
1 parent 59cc7b2 commit 6908b0a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions khiops/core/internals/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def copy_from_local(uri_or_path, local_path):
Raises
------
RuntimeError
If there was a problem when removing.
If there was a problem when copying.
"""
create_resource(uri_or_path).copy_from_local(local_path)

Expand All @@ -272,7 +272,7 @@ def copy_to_local(uri_or_path, local_path):
Raises
------
RuntimeError
If there was a problem when removing.
If there was a problem when copying.
"""
create_resource(uri_or_path).copy_to_local(local_path)

Expand Down Expand Up @@ -668,16 +668,15 @@ def remove(self):
)

def copy_from_local(self, local_path):
response = self.s3_client.Bucket(self.uri_info.netloc).upload_file(
local_path, self.uri_info.path[1:]
)
status_code = response["ResponseMetadata"]["HTTPStatusCode"]
copy_ok = 200 <= status_code <= 299
if not copy_ok:
raise RuntimeError(
f"S3 copy_from_local failed {self.uri} with code {status_code}: "
+ json.dumps(response)
# boto3.s3.transfer.upload_file is not expected to return an HTTP response
# but instead raises a S3UploadFailedError exception in case of error
try:
self.s3_client.Bucket(self.uri_info.netloc).upload_file(
local_path, self.uri_info.path[1:]
)
# normalize the raised exception
except Exception as e:
raise RuntimeError(f"S3 copy_from_local failed {self.uri}") from e

def copy_to_local(self, local_path):
response = self.s3_client.Bucket(self.uri_info.netloc).download_file(
Expand Down

0 comments on commit 6908b0a

Please sign in to comment.