Skip to content

Commit f4187a6

Browse files
committed
refining client exception handling in is_object
1 parent e220853 commit f4187a6

File tree

2 files changed

+12
-5
lines changed
  • src/aibs_informatics_aws_utils
  • test/aibs_informatics_aws_utils

2 files changed

+12
-5
lines changed

src/aibs_informatics_aws_utils/s3.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,12 @@ def is_object(s3_path: S3URI, **kwargs) -> bool:
433433
s3 = get_s3_client(**kwargs)
434434
try:
435435
s3.head_object(Bucket=s3_path.bucket, Key=s3_path.key)
436-
except ClientError:
437-
return False
436+
except ClientError as e:
437+
if client_error_code_check(e, "404", "NoSuchKey", "NotFound"):
438+
return False
439+
raise AWSError(
440+
f"Error checking existence of {s3_path}: {get_client_error_message(e)}"
441+
) from e
438442
return True
439443

440444

@@ -512,8 +516,12 @@ def is_folder_placeholder_object(s3_path: S3URI, **kwargs) -> bool:
512516
try:
513517
obj = s3.head_object(Bucket=s3_path.bucket, Key=s3_path.key)
514518
return obj["ContentLength"] == 0
515-
except ClientError:
516-
return False
519+
except ClientError as e:
520+
if client_error_code_check(e, "404", "NoSuchKey", "NotFound"):
521+
return False
522+
raise AWSError(
523+
f"Error checking existence of {s3_path}: {get_client_error_message(e)}"
524+
) from e
517525

518526

519527
def get_s3_path_collection_stats(*s3_paths: S3URI, **kwargs) -> Mapping[S3URI, S3PathStats]:

test/aibs_informatics_aws_utils/test_s3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,6 @@ def test__check_paths_in_sync__allows_subset_when_specified(self):
10971097
assert check_paths_in_sync(source_s3_path, dest_path, allow_subset=False) is False
10981098
assert check_paths_in_sync(source_s3_path, dest_s3_path, allow_subset=False) is False
10991099

1100-
11011100
def test__check_paths_in_sync__handles_sorting_issues__folders_same(self):
11021101
source_path = self.tmp_path()
11031102
(source_path / "a.txt").write_text("hello")

0 commit comments

Comments
 (0)