From a9c1c17182c42366205079a61cd97689712d6e98 Mon Sep 17 00:00:00 2001 From: Dilyan Marinov <91800778+DeltaMichael@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:20:31 +0200 Subject: [PATCH] vdk-plugins: replace report_and_rethrow (#3057) ## Why? Calling report_and_rethrow causes confusing stack traces, because of adding an extra frame from the extra function call ## What? Replace report_and_rethrow with just calling report and raising the exception after ## How was this tested? CI ## What kind of change is this? Feature/non-breaking Signed-off-by: Dilyan Marinov --- .../src/vdk/plugin/impala/impala_helper.py | 15 ++++++++------- .../templates/template_arguments_validator.py | 3 ++- .../vdk/plugin/ingest_http/ingest_over_http.py | 3 ++- .../plugin/kerberos/minikerberos_authenticator.py | 3 ++- .../src/vdk/plugin/postgres/ingest_to_postgres.py | 5 ++--- .../vdk/plugin/snowflake/snowflake_connection.py | 3 ++- .../src/vdk/plugin/sqlite/ingest_to_sqlite.py | 5 +++-- .../src/vdk/plugin/trino/ingest_to_trino.py | 3 ++- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_helper.py b/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_helper.py index 4f2167c2d0..3c84d7b688 100644 --- a/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_helper.py +++ b/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_helper.py @@ -5,6 +5,7 @@ import pyarrow from vdk.internal.core import errors +from vdk.internal.core.errors import ResolvableBy from vdk.internal.core.errors import UserCodeError from vdk.plugin.impala import impala_error_classifier from vdk.plugin.impala.impala_connection import ImpalaConnection @@ -21,14 +22,14 @@ def get_table_description(self, table_name): return self._db_connection.execute_query(f"DESCRIBE formatted {table_name}") except Exception as e: if impala_error_classifier._is_authorization_error(e): - errors.report_and_rethrow( - UserCodeError( - f"Data loading into table {table_name} has failed.", - f"You are trying to load data into a table which you do not have access to or it does not " - f"exist: {table_name}. Data load will be aborted.", - "Make sure that the destination table exists and you have access to it.", - ) + ex = UserCodeError( + f"Data loading into table {table_name} has failed.", + f"You are trying to load data into a table which you do not have access to or it does not " + f"exist: {table_name}. Data load will be aborted.", + "Make sure that the destination table exists and you have access to it.", ) + errors.report(ResolvableBy.USER, ex) + raise ex else: raise e diff --git a/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/templates/template_arguments_validator.py b/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/templates/template_arguments_validator.py index f11a5d7326..e453748cd0 100644 --- a/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/templates/template_arguments_validator.py +++ b/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/templates/template_arguments_validator.py @@ -58,4 +58,5 @@ def _validate_args(self, args: dict) -> dict: try: return self.TemplateParams(**args).dict() except ValidationError as error: - errors.report_and_rethrow(ResolvableBy.USER_ERROR, error) + errors.report(ResolvableBy.USER_ERROR, error) + raise error diff --git a/projects/vdk-plugins/vdk-ingest-http/src/vdk/plugin/ingest_http/ingest_over_http.py b/projects/vdk-plugins/vdk-ingest-http/src/vdk/plugin/ingest_http/ingest_over_http.py index 9b78a54ebe..547ebfbd76 100644 --- a/projects/vdk-plugins/vdk-ingest-http/src/vdk/plugin/ingest_http/ingest_over_http.py +++ b/projects/vdk-plugins/vdk-ingest-http/src/vdk/plugin/ingest_http/ingest_over_http.py @@ -228,4 +228,5 @@ def __send_data(self, data, http_url, headers) -> IngestionResult: } ) except Exception as e: - errors.report_and_rethrow(ResolvableBy.PLATFORM_ERROR, e) + errors.report(ResolvableBy.PLATFORM_ERROR, e) + raise e diff --git a/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py b/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py index e9083aea02..c74a4d145b 100644 --- a/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py +++ b/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py @@ -138,4 +138,5 @@ async def get_tgt(): ) except Exception as e: log.warning("Could not retrieve Kerberos TGT") - errors.report_and_rethrow(ResolvableBy.CONFIG_ERROR, e) + errors.report(ResolvableBy.CONFIG_ERROR, e) + raise e diff --git a/projects/vdk-plugins/vdk-postgres/src/vdk/plugin/postgres/ingest_to_postgres.py b/projects/vdk-plugins/vdk-postgres/src/vdk/plugin/postgres/ingest_to_postgres.py index 2022a3f5e6..bb8ee57bfb 100644 --- a/projects/vdk-plugins/vdk-postgres/src/vdk/plugin/postgres/ingest_to_postgres.py +++ b/projects/vdk-plugins/vdk-postgres/src/vdk/plugin/postgres/ingest_to_postgres.py @@ -51,9 +51,8 @@ def ingest_payload( connection.commit() log.debug("Payload was ingested.") except Exception as e: - errors.report_and_rethrow( - errors.find_whom_to_blame_from_exception(e), e - ) + errors.report(errors.find_whom_to_blame_from_exception(e), e) + raise e @staticmethod def _populate_query_parameters_tuple( diff --git a/projects/vdk-plugins/vdk-snowflake/src/vdk/plugin/snowflake/snowflake_connection.py b/projects/vdk-plugins/vdk-snowflake/src/vdk/plugin/snowflake/snowflake_connection.py index a2650f3622..6a5ce2372f 100644 --- a/projects/vdk-plugins/vdk-snowflake/src/vdk/plugin/snowflake/snowflake_connection.py +++ b/projects/vdk-plugins/vdk-snowflake/src/vdk/plugin/snowflake/snowflake_connection.py @@ -78,7 +78,8 @@ def _connect(self) -> PEP249Connection: except (errors.BaseVdkError, ProgrammingError, Exception) as e: blamee = ResolvableBy.CONFIG_ERROR log.warning("Connecting to Snowflake FAILED.") - errors.report_and_rethrow(blamee, e) + errors.report(blamee, e) + raise e def execute_query(self, query) -> List[List[Any]]: try: diff --git a/projects/vdk-plugins/vdk-sqlite/src/vdk/plugin/sqlite/ingest_to_sqlite.py b/projects/vdk-plugins/vdk-sqlite/src/vdk/plugin/sqlite/ingest_to_sqlite.py index be9393a9e5..6875924d4e 100644 --- a/projects/vdk-plugins/vdk-sqlite/src/vdk/plugin/sqlite/ingest_to_sqlite.py +++ b/projects/vdk-plugins/vdk-sqlite/src/vdk/plugin/sqlite/ingest_to_sqlite.py @@ -99,9 +99,10 @@ def __ingest_payload( log.warning( "Failed to sent payload. An issue with the SQL query occurred." ) - errors.report_and_rethrow(ResolvableBy.USER_ERROR, e) + errors.report(ResolvableBy.USER_ERROR, e) else: - errors.report_and_rethrow(errors.ResolvableBy.PLATFORM_ERROR, e) + errors.report(errors.ResolvableBy.PLATFORM_ERROR, e) + raise e def __check_destination_table_exists( self, destination_table: str, cur: Cursor diff --git a/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py b/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py index a7e26bdc2b..51f5dc2950 100644 --- a/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py +++ b/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py @@ -78,7 +78,8 @@ def _ingest_payload( cur.fetchall() log.debug("Payload was ingested.") except Exception as e: - errors.report_and_rethrow(errors.find_whom_to_blame_from_exception(e), e) + errors.report(errors.find_whom_to_blame_from_exception(e), e) + raise e @staticmethod def __to_bool(value: Any) -> bool: