1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #25404 -- Added line numbers to TemplateSyntaxError strings.

This makes it much easier to diagnose a test failure when all
you have is the stack trace from an uncaught TemplateSyntaxError.
This commit is contained in:
Dave Smith
2015-09-10 21:05:00 -06:00
committed by Tim Graham
parent d731cf5caf
commit b53b4d5c10
4 changed files with 31 additions and 12 deletions

View File

@@ -470,7 +470,7 @@ class Parser(object):
self.extend_nodelist(nodelist, TextNode(token.contents), token)
elif token.token_type == 1: # TOKEN_VAR
if not token.contents:
raise self.error(token, 'Empty variable tag')
raise self.error(token, 'Empty variable tag on line %d' % token.lineno)
try:
filter_expression = self.compile_filter(token.contents)
except TemplateSyntaxError as e:
@@ -481,7 +481,7 @@ class Parser(object):
try:
command = token.contents.split()[0]
except IndexError:
raise self.error(token, 'Empty block tag')
raise self.error(token, 'Empty block tag on line %d' % token.lineno)
if command in parse_until:
# A matching token has been reached. Return control to
# the caller. Put the token back on the token list so the
@@ -545,13 +545,23 @@ class Parser(object):
def invalid_block_tag(self, token, command, parse_until=None):
if parse_until:
raise self.error(token, "Invalid block tag: '%s', expected %s" %
(command, get_text_list(["'%s'" % p for p in parse_until])))
raise self.error(token, "Invalid block tag: '%s'" % command)
raise self.error(
token,
"Invalid block tag on line %d: '%s', expected %s" % (
token.lineno,
command,
get_text_list(["'%s'" % p for p in parse_until]),
),
)
raise self.error(token, "Invalid block tag on line %d: '%s'" % (token.lineno, command))
def unclosed_block_tag(self, parse_until):
command, token = self.command_stack.pop()
msg = "Unclosed tag '%s'. Looking for one of: %s." % (command, ', '.join(parse_until))
msg = "Unclosed tag on line %d: '%s'. Looking for one of: %s." % (
token.lineno,
command,
', '.join(parse_until),
)
raise self.error(token, msg)
def next_token(self):