Skip to content

Commit

Permalink
Show full error info in debug log for databricks-sql-connector 2.0 (#87)
Browse files Browse the repository at this point in the history
### Description

Shows full error info in debug log for `databricks-sql-connector 2.0`.

The way to hold error info was changed in `databricks-sql-connector 2.0`.
We should show the full error info in the debug log.
  • Loading branch information
ueshin authored Apr 30, 2022
1 parent 8295a82 commit 2ed551d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions dbt/adapters/databricks/connections.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextlib import contextmanager
from distutils.version import LooseVersion
from dataclasses import dataclass
import re
import time
Expand All @@ -22,7 +23,7 @@
Connection as DatabricksSQLConnection,
Cursor as DatabricksSQLCursor,
)
from databricks.sql.exc import OperationalError
from databricks.sql.exc import DatabaseError, OperationalError

logger = AdapterLogger("Databricks")

Expand Down Expand Up @@ -157,17 +158,26 @@ def exception_handler(self, sql: str) -> Iterator[None]:
try:
yield

except OperationalError as exc:
logger.debug("Error while running:\n{}".format(sql))
logger.debug(exc)
msg = str(exc)
m = self.DROP_JAVA_STACKTRACE_REGEX.search(msg)
if m:
msg = ("Query execution failed.\nError message: {}").format(m.group().strip())
raise dbt.exceptions.RuntimeException(msg)

except Exception as exc:
logger.debug("Error while running:\n{}".format(sql))
if isinstance(exc, OperationalError) and LooseVersion(dbsql.__version__) < "2.0":
logger.debug(f"Error while running:\n{sql}")
logger.debug(exc)
msg = str(exc)
m = self.DROP_JAVA_STACKTRACE_REGEX.search(msg)
if m:
msg = f"Query execution failed.\nError message: {m.group().strip()}"
raise dbt.exceptions.RuntimeException(msg)
elif isinstance(exc, DatabaseError):
logger.debug(f"Error while running:\n{sql}")
logger.debug(exc)
if hasattr(exc, "context"):
if "operation-id" in exc.context:
logger.debug(f"operation-id: {exc.context['operation-id']}")
if "diagnostic-info" in exc.context:
logger.debug(f"diagnostic-info: {exc.context['diagnostic-info']}")
raise dbt.exceptions.RuntimeException(str(exc))

logger.debug(f"Error while running:\n{sql}")
logger.debug(exc)
if len(exc.args) == 0:
raise
Expand Down

0 comments on commit 2ed551d

Please sign in to comment.