SIENTIAPDE-1248: Refactor MinIO activity to raise specific exception types for better error handling
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -56,7 +56,7 @@ def test___init___failure(mock_boto3_client):
|
||||
logger = MagicMock()
|
||||
notification_handler = MagicMock()
|
||||
|
||||
with raises(Exception, match='Failed to initialize MinIO client'):
|
||||
with raises(ConnectionError, match='Failed to initialize MinIO client'):
|
||||
MinIO(
|
||||
endpoint_url='http://localhost:9000',
|
||||
access_key='minioadmin',
|
||||
@@ -156,7 +156,7 @@ async def test_fetch_file_from_minio_file_not_found(minio):
|
||||
}
|
||||
|
||||
# Act & Assert
|
||||
with raises(Exception, match='Error fetching file from MinIO'):
|
||||
with raises(OSError, match='Error fetching file from MinIO'):
|
||||
await minio.fetch_file_from_minio(input_data)
|
||||
|
||||
# Verify notification was sent
|
||||
@@ -179,7 +179,7 @@ async def test_fetch_file_from_minio_network_error(minio):
|
||||
}
|
||||
|
||||
# Act & Assert
|
||||
with raises(Exception, match='Error fetching file from MinIO'):
|
||||
with raises(OSError, match='Error fetching file from MinIO'):
|
||||
await minio.fetch_file_from_minio(input_data)
|
||||
|
||||
minio.send_notification.assert_called_once()
|
||||
@@ -242,7 +242,7 @@ async def test_delete_file_from_minio_access_denied(minio):
|
||||
}
|
||||
|
||||
# Act & Assert
|
||||
with raises(Exception, match='Error deleting file from MinIO'):
|
||||
with raises(OSError, match='Error deleting file from MinIO'):
|
||||
await minio.delete_file_from_minio(input_data)
|
||||
|
||||
# Verify notification was sent
|
||||
@@ -265,7 +265,7 @@ async def test_delete_file_from_minio_network_error(minio):
|
||||
}
|
||||
|
||||
# Act & Assert
|
||||
with raises(Exception, match='Error deleting file from MinIO'):
|
||||
with raises(OSError, match='Error deleting file from MinIO'):
|
||||
await minio.delete_file_from_minio(input_data)
|
||||
|
||||
minio.send_notification.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user