From 6d7e453bafe4589e9787e32b26e959ec859930d9 Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Sun, 1 Mar 2020 20:32:23 -0700 Subject: [PATCH] PR feedback: Add exception handler around macro execution, add a message about what is going on when list_schemas fails --- core/dbt/adapters/base/impl.py | 11 ++++++----- core/dbt/task/runnable.py | 1 + .../snowflake/dbt/adapters/snowflake/impl.py | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/core/dbt/adapters/base/impl.py b/core/dbt/adapters/base/impl.py index d8e638443fd..8600560b1d7 100644 --- a/core/dbt/adapters/base/impl.py +++ b/core/dbt/adapters/base/impl.py @@ -961,11 +961,12 @@ def execute_macro( macro_function = MacroGenerator(macro, macro_context) - try: - result = macro_function(**kwargs) - finally: - if release: - self.release_connection() + with self.connections.exception_handler(f'macro {macro_name}'): + try: + result = macro_function(**kwargs) + finally: + if release: + self.release_connection() return result @classmethod diff --git a/core/dbt/task/runnable.py b/core/dbt/task/runnable.py index 33e6a78ff58..1bb5983a19b 100644 --- a/core/dbt/task/runnable.py +++ b/core/dbt/task/runnable.py @@ -418,6 +418,7 @@ def list_schemas(db: str) -> List[Tuple[str, str]]: ] def create_schema(db: str, schema: str) -> None: + assert False with adapter.connection_named(f'create_{db}_{schema}'): adapter.create_schema(db, schema) diff --git a/plugins/snowflake/dbt/adapters/snowflake/impl.py b/plugins/snowflake/dbt/adapters/snowflake/impl.py index 267cebf6136..37e27dcb2de 100644 --- a/plugins/snowflake/dbt/adapters/snowflake/impl.py +++ b/plugins/snowflake/dbt/adapters/snowflake/impl.py @@ -8,7 +8,7 @@ from dbt.adapters.snowflake import SnowflakeRelation from dbt.adapters.snowflake import SnowflakeColumn from dbt.contracts.graph.manifest import Manifest -from dbt.exceptions import RuntimeException +from dbt.exceptions import RuntimeException, DatabaseException from dbt.utils import filter_null_values @@ -84,10 +84,17 @@ def post_model_hook( self._use_warehouse(context) def list_schemas(self, database: str) -> List[str]: - results = self.execute_macro( - LIST_SCHEMAS_MACRO_NAME, - kwargs={'database': database} - ) + try: + results = self.execute_macro( + LIST_SCHEMAS_MACRO_NAME, + kwargs={'database': database} + ) + except DatabaseException as exc: + msg = ( + f'Database error while listing schemas in database ' + f'"{database}"\n{exc}' + ) + raise RuntimeException(msg) # this uses 'show terse schemas in database', and the column name we # want is 'name'