diff --git a/.changes/unreleased/Fixes-20241202-090803.yaml b/.changes/unreleased/Fixes-20241202-090803.yaml new file mode 100644 index 00000000..fcf1d1c5 --- /dev/null +++ b/.changes/unreleased/Fixes-20241202-090803.yaml @@ -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" diff --git a/dbt_common/clients/jinja.py b/dbt_common/clients/jinja.py index 2cee9228..8cc1205a 100644 --- a/dbt_common/clients/jinja.py +++ b/dbt_common/clients/jinja.py @@ -46,6 +46,7 @@ MaterializationArgError, JinjaRenderingError, UndefinedCompilationError, + DbtRuntimeError, ) from dbt_common.exceptions.macros import MacroReturn, UndefinedMacroError, CaughtMacroError @@ -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] = {}