From b0be5f2dade91053df773ea2149d558b8e61a446 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Fri, 30 Aug 2024 05:43:30 +0000 Subject: [PATCH] Print the name of faulty jinja templates in pre-commit (#11484) --- tests/scripts/check-templates.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/scripts/check-templates.py b/tests/scripts/check-templates.py index 1092a0d3e..3c94dfb29 100755 --- a/tests/scripts/check-templates.py +++ b/tests/scripts/check-templates.py @@ -1,9 +1,20 @@ #!/usr/bin/env python import sys +import traceback from jinja2 import Environment +from jinja2.exceptions import TemplateSyntaxError + env = Environment() +errors = False for template in sys.argv[1:]: - with open(template) as t: - env.parse(t.read()) + try: + with open(template) as t: + env.parse(t.read()) + except TemplateSyntaxError as e: + print (template) + traceback.print_exc() + errors = True +if errors: + exit (1)