From e124942858f4077fc12d8b0adbf59593591feb53 Mon Sep 17 00:00:00 2001 From: Irene Dea Date: Thu, 12 Sep 2024 18:08:15 +0000 Subject: [PATCH] Add permissions check --- .../command_utils/data_prep/convert_delta_to_json.py | 8 ++++++++ llmfoundry/utils/exceptions.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/llmfoundry/command_utils/data_prep/convert_delta_to_json.py b/llmfoundry/command_utils/data_prep/convert_delta_to_json.py index 50d11b1222..aaecabc644 100644 --- a/llmfoundry/command_utils/data_prep/convert_delta_to_json.py +++ b/llmfoundry/command_utils/data_prep/convert_delta_to_json.py @@ -22,6 +22,7 @@ ClusterDoesNotExistError, FailedToConnectToDatabricksError, FailedToCreateSQLConnectionError, + InsufficientPermissionsError, ) if TYPE_CHECKING: @@ -454,6 +455,13 @@ def fetch( sparkSession, ) except Exception as e: + from pyspark.errors import AnalysisException + if isinstance(e, AnalysisException): + if 'INSUFFICIENT_PERMISSIONS' in e.message: + raise InsufficientPermissionsError( + action= + f'reading from {tablename}. Please check your permissions.', + ) from e raise RuntimeError( f'Error in get rows from {tablename}. Restart sparkSession and try again', ) from e diff --git a/llmfoundry/utils/exceptions.py b/llmfoundry/utils/exceptions.py index 345a254407..519d0593c7 100644 --- a/llmfoundry/utils/exceptions.py +++ b/llmfoundry/utils/exceptions.py @@ -427,3 +427,11 @@ def __init__( window_size=window_size, loss_window=loss_window, ) + + +class InsufficientPermissionsError(UserError): + """Error thrown when the user does not have sufficient permissions.""" + + def __init__(self, action: str) -> None: + message = f'Insufficient permissions when {action}.' + super().__init__(message, action=action)