SIENTIAPDE-1248: Refactor MinIO activity to raise specific exception types for better error handling

This commit is contained in:
Bruno Domingues
2025-10-06 10:58:48 -03:00
parent ec5b9df125
commit 520975e7aa
2 changed files with 11 additions and 11 deletions

View File

@@ -71,7 +71,7 @@ class MinIO(BaseActivity):
notification_handler: Notification handler for alerts and monitoring
Raises:
Exception: If boto3 client initialization fails
ConnectionError: If boto3 client initialization fails
"""
BaseActivity.__init__(self, logger, notification_handler, set_error_counter=True)
self.endpoint_url = endpoint_url
@@ -109,7 +109,7 @@ class MinIO(BaseActivity):
except Exception as e:
error_msg = f'Failed to initialize MinIO client: {str(e)}'
self.error(error_msg)
raise Exception(error_msg) from e
raise ConnectionError(error_msg) from e
@activity.defn(name='fetch_file_from_minio')
async def fetch_file_from_minio(self, input_data: dict[str, Any]) -> BytesIO:
@@ -137,7 +137,7 @@ class MinIO(BaseActivity):
BytesIO: File content as a file-like object
Raises:
Exception: If file fetch fails due to network, permission, or other errors
OSError: If file fetch fails due to network, permission, or other errors
"""
metadata = input_data.get('metadata', {})
bucket_name = input_data['bucket_name']
@@ -173,7 +173,7 @@ class MinIO(BaseActivity):
attachment_content=trace,
)
self.error(trace, metadata=metadata)
raise Exception(error_msg) from e
raise OSError(error_msg) from e
@activity.defn(name='delete_file_from_minio')
async def delete_file_from_minio(self, input_data: dict[str, Any]) -> None:
@@ -199,7 +199,7 @@ class MinIO(BaseActivity):
None
Raises:
Exception: If file deletion fails due to permission or other errors
OSError: If file deletion fails due to permission or other errors
"""
metadata = input_data.get('metadata', {})
bucket_name = input_data['bucket_name']
@@ -226,4 +226,4 @@ class MinIO(BaseActivity):
attachment_content=trace,
)
self.error(trace, metadata=metadata)
raise Exception(error_msg) from e
raise OSError(error_msg) from e