Skip to content

Commit

Permalink
add project names/filenames/values to rendering errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed May 29, 2020
1 parent ee6b842 commit 3b1c6e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## dbt 0.17.0 (Release TBD)

### Fixes
- Added filename, project, and the value that failed to render to the exception raised when rendering fails. ([#2499](https://github.com/fishtown-analytics/dbt/issues/2499), [#2501](https://github.com/fishtown-analytics/dbt/pull/2501))


### Under the hood
- Lock protobufs to the last version that had fully functioning releases on all supported platforms ([#2490](https://github.com/fishtown-analytics/dbt/issues/2490), [#2491](https://github.com/fishtown-analytics/dbt/pull/2491))

Expand Down
17 changes: 12 additions & 5 deletions core/dbt/config/renderer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Dict, Any, Tuple, Optional, Union

from dbt.clients.jinja import get_rendered
from dbt.clients.jinja import get_rendered, catch_jinja

from dbt.exceptions import DbtProjectError
from dbt.exceptions import RecursionException
from dbt.exceptions import (
DbtProjectError, CompilationException, RecursionException
)
from dbt.node_types import NodeType
from dbt.utils import deep_map

Expand Down Expand Up @@ -35,7 +36,12 @@ def render_value(
# if it wasn't read as a string, ignore it
if not isinstance(value, str):
return value
return get_rendered(value, self.context, native=True)
try:
with catch_jinja():
return get_rendered(value, self.context, native=True)
except CompilationException as exc:
msg = f'Could not render {value}: {exc.msg}'
raise CompilationException(msg) from exc

def render_data(
self, data: Dict[str, Any]
Expand Down Expand Up @@ -118,7 +124,8 @@ def render_data(
self.version = data.get('current-version')

try:
return deep_map(self.render_entry, data)
with catch_jinja():
return deep_map(self.render_entry, data)
except RecursionException:
raise DbtProjectError(
f'Cycle detected: {self.name} input has a reference to itself',
Expand Down
9 changes: 8 additions & 1 deletion core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,14 @@ def parse_file(self, block: FileBlock) -> None:
# mark the file as seen, even if there are no macros in it
self.results.get_file(block.file)
if dct:
dct = self.raw_renderer.render_data(dct)
try:
dct = self.raw_renderer.render_data(dct)
except CompilationException as exc:
raise CompilationException(
f'Failed to render {block.path.original_file_path} from '
f'project {self.project.project_name}: {exc}'
) from exc

yaml_block = YamlBlock.from_file_block(block, dct)

self._parse_format_version(yaml_block)
Expand Down

0 comments on commit 3b1c6e5

Please sign in to comment.