Skip to content

Commit

Permalink
PR feedback: Add exception handler around macro execution, add a mess…
Browse files Browse the repository at this point in the history
…age about what is going on when list_schemas fails
  • Loading branch information
Jacob Beck committed Mar 2, 2020
1 parent c59adc3 commit 47cef1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 6 additions & 5 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions plugins/snowflake/dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'

Expand Down

0 comments on commit 47cef1d

Please sign in to comment.