Skip to content

Commit

Permalink
Added extra exception handling on bucket_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
nmassey001 committed Feb 3, 2025
1 parent 2d87b1d commit af19cb8
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions nlds_processors/transfer/get_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import minio
from minio.error import S3Error
from retry import retry
from urllib3.exceptions import HTTPError

from nlds_processors.transfer.base_transfer import BaseTransferConsumer
from nlds.rabbit.consumer import State
Expand Down Expand Up @@ -76,14 +77,29 @@ def _get_and_check_bucket_name_object_name(self, path_details):
)
raise TransferError(message=reason)

if bucket_name and not self.client.bucket_exists(bucket_name):
# If bucket doesn't exist then pass for failure
reason = f"Bucket {bucket_name} does not exist"
# try to get the bucket - may throw exception if user does not have access
# permissions
try:
bucket_exists = self.client.bucket_exists(bucket_name)
except (S3Error, HTTPError) as e:
reason = (
f"Could not verify that bucket {bucket_name} exists during get "
f"transfer. Original exception: {e}"
)
self.log(
f"{reason}. Adding {path_details.object_name} to failed list.",
f"{reason}. Adding {path_details.object_name} to failed list. ",
RK.LOG_ERROR,
)
raise TransferError(message=reason)
else:
if bucket_name and not bucket_exists:
# If bucket doesn't exist then pass for failure
reason = f"Bucket {bucket_name} does not exist"
self.log(
f"{reason}. Adding {path_details.object_name} to failed list.",
RK.LOG_ERROR,
)
raise TransferError(message=reason)

return bucket_name, object_name

Expand Down

0 comments on commit af19cb8

Please sign in to comment.