From b3fc73c303ce827cac5ee25c5295522e93221964 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Wed, 4 Dec 2024 10:26:15 -0500 Subject: [PATCH] catch generic exception in catch_jinja and reraise as CompilationError (#224) * catch generic exception in catch_jinja and reraise as CompilationError * changelog entry * Propagate dbt exception raised during jinja compilation --- .changes/unreleased/Fixes-20241202-090803.yaml | 6 ++++++ dbt_common/clients/jinja.py | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 .changes/unreleased/Fixes-20241202-090803.yaml 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] = {}