Skip to content

Commit

Permalink
vdk-plugins: replace report_and_rethrow (#3057)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
DeltaMichael authored Jan 29, 2024
1 parent ed8abf4 commit a9c1c17
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a9c1c17

Please sign in to comment.