Skip to content

Commit

Permalink
fix commit messages by using the stack properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Mar 24, 2020
1 parent 0a382c4 commit 06b74d6
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes
- When a jinja value is undefined, give a helpful error instead of failing with cryptic "cannot pickle ParserMacroCapture" errors ([#2110](https://github.com/fishtown-analytics/dbt/issues/2110), [#2184](https://github.com/fishtown-analytics/dbt/pull/2184))
- Added timeout to registry download call ([#2195](https://github.com/fishtown-analytics/dbt/issues/2195), [#2228](https://github.com/fishtown-analytics/dbt/pull/2228))
- When a macro is called with invalid arguments, include the calling model in the output ([#2073](https://github.com/fishtown-analytics/dbt/issues/2073), [#2238](https://github.com/fishtown-analytics/dbt/pull/2238))

Contributors:
- [@raalsky](https://github.com/Raalsky) ([#2224](https://github.com/fishtown-analytics/dbt/pull/2224), [#2228](https://github.com/fishtown-analytics/dbt/pull/2228))
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ def catch_jinja(node=None) -> Iterator[None]:
raise CompilationException(str(e), node) from e
except jinja2.exceptions.UndefinedError as e:
raise CompilationException(str(e), node) from e
except CompilationException as exc:
exc.add_node(node)
raise


def parse(string):
Expand Down
9 changes: 7 additions & 2 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def __init__(self, msg, node=None):
self.node = node
self.msg = msg

def add_node(self, node=None):
if node is not None and node is not self.node:
if self.node is not None:
self.stack.append(self.node)
self.node = node

@property
def type(self):
return 'Runtime'
Expand Down Expand Up @@ -849,8 +855,7 @@ def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except RuntimeException as exc:
if exc.node is None:
exc.node = model
exc.add_node(model)
raise exc
return inner
return wrap
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/node_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def compile_and_execute(self, manifest, ctx):

def _handle_catchable_exception(self, e, ctx):
if e.node is None:
e.node = ctx.node
e.add_node(ctx.node)

logger.debug(str(e), exc_info=True)
return str(e)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def parse_block(self, block: FullBlock) -> Iterable[ParsedDocumentation]:
try:
template = get_template(block.contents, {})
except CompilationException as e:
e.node = base_node
e.add_node(base_node)
raise
all_docs = list(self._parse_template_docs(template, base_node))
if len(all_docs) != 1:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def parse_unparsed_macros(
try:
ast = jinja.parse(block.full_block)
except CompilationException as e:
e.node = base_node
e.add_node(base_node)
raise e

macro_nodes = list(ast.find_all(jinja2.nodes.Macro))
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def extract_blocks(self, source_file: FileBlock) -> Iterable[BlockTag]:

except CompilationException as exc:
if exc.node is None:
exc.node = source_file
exc.add_node(source_file)
raise

def __iter__(self) -> Iterator[BlockSearchResult]:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/rpc/node_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def handle_exception(self, e, ctx):
logger.debug('Got an exception: {}'.format(e), exc_info=True)
if isinstance(e, dbt.exceptions.Exception):
if isinstance(e, dbt.exceptions.RuntimeException):
e.node = ctx.node
e.add_node(ctx.node)
return dbt_error(e)
elif isinstance(e, RPCException):
return e
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro some_macro(arg) %}
{{ arg }}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ some_macro(invalid='test') }}
select 1 as id
28 changes: 28 additions & 0 deletions test/integration/011_invalid_model_tests/test_invalid_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,31 @@ def test_postgres_view_with_incremental_attributes(self):
self.run_dbt()

self.assertIn('which was not found', str(exc.exception))


class TestInvalidMacroCall(DBTIntegrationTest):
@property
def schema(self):
return "invalid_models_011"

@property
def models(self):
return "models-4"

@staticmethod
def dir(path):
return path.lstrip("/")

@property
def project_config(self):
return {
'macro-paths': [self.dir('bad-macros')],
}

@use_profile('postgres')
def test_postgres_call_invalid(self):
with self.assertRaises(Exception) as exc:
self.run_dbt(['compile'])

self.assertIn('> in macro some_macro (bad-macros/macros.sql)', str(exc.exception))
self.assertIn('> called by model bad_macro (models-4/bad_macro.sql', str(exc.exception))

0 comments on commit 06b74d6

Please sign in to comment.