From a2ccc9ee350863e42e36119b8c60dc5e6ce85860 Mon Sep 17 00:00:00 2001 From: v-chen_data Date: Thu, 26 Sep 2024 15:32:53 -0700 Subject: [PATCH] insufficient errors --- .../data_prep/convert_delta_to_json.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 fbbc5f2cd9..b23655d5f5 100644 --- a/llmfoundry/command_utils/data_prep/convert_delta_to_json.py +++ b/llmfoundry/command_utils/data_prep/convert_delta_to_json.py @@ -228,7 +228,22 @@ def run_query( if method == 'dbsql': if cursor is None: raise ValueError(f'cursor cannot be None if using method dbsql') - cursor.execute(query) + try: + cursor.execute(query) + except Exception as e: + from databricks.sql.exc import ServerOperationError + if isinstance(e, ServerOperationError): + if 'INSUFFICIENT_PERMISSIONS' in e.message: # pyright: ignore + match = re.search( + r"'([^']+)'", + e.message, # pyright: ignore + ) + if match: + table_name = match.group(1) + action = f'accessing table {table_name}' + else: + action = 'accessing table' + raise InsufficientPermissionsError(action=action,) from e if collect: return cursor.fetchall() elif method == 'dbconnect':