From a0b9cf700be87b8a52bbfdae4e8c3dc83885bc7e Mon Sep 17 00:00:00 2001 From: Sanjeev kumar N Date: Thu, 22 Sep 2022 17:05:59 +0530 Subject: [PATCH] Add http error identification for credentials and hostname errors (#90) * Internal ticket: https://jira.cloudera.com/browse/DBT-398 The error printed seems to be generic, so adding code to identity the failure from Impala connection. Test plan: * Move into a dbt impala project and install dbt-impala from this git repo * Add profile details in your home dbt file like below, dbt_impala_demo: outputs: dev: auth_type: ldap host: {} http_path: {} password: {} port: 443 schema: dbt_impala_demo dbname: dbt_impala_demo threads: 4 type: impala use_http_transport: true use_ssl: true user: {} target: dev * Update with wrong hostname or wrong user credentials * run > dbt debug, and you should see the type of error in the console * Add below snowplow configs to your .env if you face any snowplow error SNOWPLOW_ENDPOINT=https://dcevents.cldrteam.datacoral.io/cldrteam/apievents SNOWPLOW_TIMEOUT=10 SNOWPLOW_API_KEY= SNOWPLOW_ENNV=prod Signed-off-by: Sanjeev kumar N --- dbt/adapters/impala/connections.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dbt/adapters/impala/connections.py b/dbt/adapters/impala/connections.py index 8343574..866aea5 100644 --- a/dbt/adapters/impala/connections.py +++ b/dbt/adapters/impala/connections.py @@ -32,6 +32,9 @@ from dbt.logger import GLOBAL_LOGGER as LOGGER import impala.dbapi +from impala.error import DatabaseError +from impala.error import HttpError +from impala.error import HiveServer2Error import dbt.adapters.impala.__version__ as ver import dbt.adapters.impala.cloudera_tracking as tracker @@ -113,9 +116,15 @@ def __init__(self, profile: AdapterRequiredConfig): def exception_handler(self, sql: str): try: yield - except impala.dbapi.DatabaseError as exc: - LOGGER.debug("dbt-impala error: {}".format(str(exc))) - raise dbt.exceptions.DatabaseException(str(exc)) + except HttpError as httpError: + LOGGER.debug("Authorization error: {}".format(httpError)) + raise dbt.exceptions.RuntimeException ("HTTP Authorization error: " + str(httpError) + ", please check your credentials") + except HiveServer2Error as servError: + LOGGER.debug("Server connection error: {}".format(servError)) + raise dbt.exceptions.RuntimeException ("Unable to establish connection to Impala server: " + str(servError)) + except DatabaseError as dbError: + LOGGER.debug("Database connection error: {}".format(str(dbError))) + raise dbt.exceptions.DatabaseException("Database Connection error: " + str(dbError)) except Exception as exc: LOGGER.debug("Error running SQL: {}".format(sql)) raise dbt.exceptions.RuntimeException(str(exc))