From a21ab86ca6e38a9b90a6c40f2aab87030e6f010f Mon Sep 17 00:00:00 2001 From: Marcin Juszkiewicz Date: Wed, 13 Mar 2019 15:45:22 +0100 Subject: build: handle template syntax errors better Before: (venv-for-kolla) 15:35 (s) hrw@puchatek:kolla$ ./tools/build.py --template-only INFO:kolla.common.utils:Found the docker image folder at /home/hrw/devel/linaro/kolla/docker Traceback (most recent call last): [.. here goes 100 lines of Jinja2 traceback ..] jinja2.exceptions.TemplateSyntaxError: unexpected '}', expected ']' After: (venv-for-kolla) 15:44 (s) hrw@puchatek:kolla$ ./tools/build.py --template-only INFO:kolla.common.utils:Found the docker image folder at /home/hrw/devel/linaro/kolla/docker ERROR:kolla.common.utils:Syntax error in template: ironic-inspector/Dockerfile.j2 ERROR:kolla.common.utils:unexpected '}', expected ']' INFO:kolla.common.utils:Dockerfiles are generated in /tmp/kolla-2019-03-13_15-44-28_0ovk4xu_/docker Change-Id: Iaa899f0b81f6698aa86b15977c39af3269d31e9a --- kolla/cmd/build.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/kolla/cmd/build.py b/kolla/cmd/build.py index 25facd19d..e912a6d12 100755 --- a/kolla/cmd/build.py +++ b/kolla/cmd/build.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import jinja2 import os import sys @@ -28,13 +29,18 @@ from kolla.image import build # noqa def main(): - statuses = build.run_build() - if statuses: - (bad_results, good_results, unmatched_results, - skipped_results) = statuses - if bad_results: - return 1 - return 0 + try: + statuses = build.run_build() + if statuses: + (bad_results, good_results, unmatched_results, + skipped_results) = statuses + if bad_results: + return 1 + return 0 + except jinja2.exceptions.TemplateSyntaxError as e: + build.LOG.error("Syntax error in template: %s" % e.name) + build.LOG.error(e.message) + return 1 if __name__ == '__main__': -- cgit v1.2.3