Skip to content

Commit

Permalink
catch generic exception in catch_jinja and reraise as CompilationError (
Browse files Browse the repository at this point in the history
#224)

* catch generic exception in catch_jinja and reraise as CompilationError

* changelog entry

* Propagate dbt exception raised during jinja compilation
  • Loading branch information
MichelleArk authored Dec 4, 2024
1 parent f1f6e6f commit b3fc73c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20241202-090803.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Generic exception handling during jinja compilation
time: 2024-12-02T09:08:03.599612-05:00
custom:
Author: michelleark
Issue: "225"
7 changes: 7 additions & 0 deletions dbt_common/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
MaterializationArgError,
JinjaRenderingError,
UndefinedCompilationError,
DbtRuntimeError,
)
from dbt_common.exceptions.macros import MacroReturn, UndefinedMacroError, CaughtMacroError

Expand Down Expand Up @@ -534,6 +535,12 @@ def catch_jinja(node: Optional[_NodeProtocol] = None) -> Iterator[None]:
except CompilationError as exc:
exc.add_node(node)
raise
except DbtRuntimeError:
# Propagate dbt exception raised during jinja compilation
raise
except Exception as e:
# Raise any non-dbt exceptions as CompilationError
raise CompilationError(str(e), node) from e


_TESTING_PARSE_CACHE: Dict[str, jinja2.nodes.Template] = {}
Expand Down

0 comments on commit b3fc73c

Please sign in to comment.