From 13d473a26629b643e5db214363a9c9225bb6705c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Fri, 17 Nov 2023 08:00:30 +0100 Subject: [PATCH] [DSW-2119] Fix Jinja2 template error reporting --- packages/dsw-document-worker/CHANGELOG.md | 4 ++++ .../dsw/document_worker/templates/steps/template.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/packages/dsw-document-worker/CHANGELOG.md b/packages/dsw-document-worker/CHANGELOG.md index adb3864d..1f02a501 100644 --- a/packages/dsw-document-worker/CHANGELOG.md +++ b/packages/dsw-document-worker/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed + +- Reporting Jinja2 template syntax errors + ## [4.0.0] diff --git a/packages/dsw-document-worker/dsw/document_worker/templates/steps/template.py b/packages/dsw-document-worker/dsw/document_worker/templates/steps/template.py index 895a91ac..87ce464a 100644 --- a/packages/dsw-document-worker/dsw/document_worker/templates/steps/template.py +++ b/packages/dsw-document-worker/dsw/document_worker/templates/steps/template.py @@ -127,6 +127,8 @@ def asset_path(file_name): content = b'' try: content = self.j2_root_template.render(**jinja_args).encode(DEFAULT_ENCODING) + except jinja2.exceptions.TemplateSyntaxError as e: + self.raise_exc(self._jinja_exception_msg(e)) except jinja2.exceptions.TemplateRuntimeError as e: self.raise_exc(f'Failed rendering Jinja2 template due to' f' {type(e).__name__}\n'