Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actual error seems hidden in traceback during TemplateSyntaxError #763

Closed
AlJohri opened this issue Aug 31, 2017 · 2 comments · Fixed by #1110
Closed

actual error seems hidden in traceback during TemplateSyntaxError #763

AlJohri opened this issue Aug 31, 2017 · 2 comments · Fixed by #1110
Milestone

Comments

@AlJohri
Copy link

@AlJohri AlJohri commented Aug 31, 2017

it seems like the actual error from a template designer perspective is hidden way up in the traceback:

File "./myorg/hss/football_game/pagebuilder/score_by_quarter.j2", line 145, in template
        {%- elif loop.previtem and loop.previtem.away_total > loop.previtem.home_total and period.away_total > period.home_total and period.away_total-period.home_total > loop.previtem.away_total-loop.previtem.home_total > -%}

is there a way to make the error a little nicer at the bottom of the traceback?

full traceback:

    Traceback (most recent call last):
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/tornado/web.py", line 1488, in _execute
        result = self.prepare()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/tornado/web.py", line 2774, in prepare
        self.fallback(self.request)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/livereload/server.py", line 113, in __call__
        WSGIContainer.environ(request), start_response)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
        response = self.handle_exception(e)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
        raise value
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
        response = self.full_dispatch_request()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
        raise value
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
        rv = self.dispatch_request()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "./app.py", line 46, in root
        ret = render(namespace, template, item_id)
      File "/Users/johria/Development/myproject/apps/api/stories/render.py", line 66, in render
        template = env.get_template(f'{namespace}.{template}')
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template
        return self._load_template(name, self.make_globals(globals))
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template
        template = self.loader.load(self, name, globals)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/loaders.py", line 125, in load
        code = environment.compile(source, name, filename)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 591, in compile
        self.handle_exception(exc_info, source_hint=source_hint)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
        raise value.with_traceback(tb)
      File "./myorg/hss/football_game/pagebuilder/score_by_quarter.j2", line 145, in template
        {%- elif loop.previtem and loop.previtem.away_total > loop.previtem.home_total and period.away_total > period.home_total and period.away_total-period.home_total > loop.previtem.away_total-loop.previtem.home_total > -%}
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 497, in _parse
        return Parser(self, source, name, encode_filename(filename)).parse()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 900, in parse
        result = nodes.Template(self.subparse(), lineno=1)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 882, in subparse
        rv = self.parse_statement()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 130, in parse_statement
        return getattr(self, 'parse_' + self.stream.current.value)()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 198, in parse_for
        body = self.parse_statements(('name:endfor', 'name:else'))
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 165, in parse_statements
        result = self.subparse(end_tokens)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 882, in subparse
        rv = self.parse_statement()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 130, in parse_statement
        return getattr(self, 'parse_' + self.stream.current.value)()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 222, in parse_if
        drop_needle=True)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 165, in parse_statements
        result = self.subparse(end_tokens)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 882, in subparse
        rv = self.parse_statement()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 130, in parse_statement
        return getattr(self, 'parse_' + self.stream.current.value)()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 210, in parse_if
        node.test = self.parse_tuple(with_condexpr=False)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 619, in parse_tuple
        args.append(parse())
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 611, in <lambda>
        parse = lambda: self.parse_expression(with_condexpr=False)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 432, in parse_expression
        return self.parse_or()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 449, in parse_or
        left = self.parse_and()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 460, in parse_and
        right = self.parse_not()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 469, in parse_not
        return self.parse_compare()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 479, in parse_compare
        ops.append(nodes.Operand(token_type, self.parse_math1()))
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 495, in parse_math1
        left = self.parse_concat()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 506, in parse_concat
        args = [self.parse_math2()]
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 516, in parse_math2
        left = self.parse_pow()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 527, in parse_pow
        left = self.parse_unary()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 545, in parse_unary
        node = self.parse_primary()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 582, in parse_primary
        self.fail("unexpected '%s'" % describe_token(token), token.lineno)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/parser.py", line 59, in fail
        raise exc(msg, lineno, self.name, self.filename)
    jinja2.exceptions.TemplateSyntaxError: unexpected 'end of statement block'
@davidism

This comment has been minimized.

Copy link
Member

@davidism davidism commented Dec 2, 2019

This seems to be a problem with Python 3, on Python 2 the TemplateSyntaxError is the last frame.

@AlJohri

This comment has been minimized.

Copy link
Author

@AlJohri AlJohri commented Dec 2, 2019

just in case it wasn't clear, I was advocating to have this as the ideal traceback:

    Traceback (most recent call last):
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/tornado/web.py", line 1488, in _execute
        result = self.prepare()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/tornado/web.py", line 2774, in prepare
        self.fallback(self.request)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/livereload/server.py", line 113, in __call__
        WSGIContainer.environ(request), start_response)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
        response = self.handle_exception(e)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
        raise value
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
        response = self.full_dispatch_request()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
        raise value
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
        rv = self.dispatch_request()
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "./app.py", line 46, in root
        ret = render(namespace, template, item_id)
      File "/Users/johria/Development/myproject/apps/api/stories/render.py", line 66, in render
        template = env.get_template(f'{namespace}.{template}')
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template
        return self._load_template(name, self.make_globals(globals))
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template
        template = self.loader.load(self, name, globals)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/loaders.py", line 125, in load
        code = environment.compile(source, name, filename)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 591, in compile
        self.handle_exception(exc_info, source_hint=source_hint)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/johria/.virtualenvs/myproject/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
        raise value.with_traceback(tb)
      File "./myorg/hss/football_game/pagebuilder/score_by_quarter.j2", line 145, in template
        {%- elif loop.previtem and loop.previtem.away_total > loop.previtem.home_total and period.away_total > period.home_total and period.away_total-period.home_total > loop.previtem.away_total-loop.previtem.home_total > -%}

where the offending jinja2 line appears at the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.