This fixes #368.
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 11 Feb 2010 13:27:23 +0000 (14:27 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 11 Feb 2010 13:27:23 +0000 (14:27 +0100)
--HG--
branch : trunk

jinja2/parser.py
jinja2/testsuite/lexnparse.py

index 96980d1c9af66c71b0cc6c9c7e889bf08cc23af2..1f5e12a721c71af9fd2b00e719ec04f89cf783b4 100644 (file)
@@ -54,21 +54,26 @@ class Parser(object):
         expected = []
         for exprs in end_token_stack:
             expected.extend(map(describe_token_expr, exprs))
-        currently_looking = ' or '.join("'%s'" % describe_token_expr(expr)
-                                        for expr in end_token_stack[-1])
+        if end_token_stack:
+            currently_looking = ' or '.join(
+                "'%s'" % describe_token_expr(expr)
+                for expr in end_token_stack[-1])
+        else:
+            currently_looking = None
 
         if name is None:
             message = ['Unexpected end of template.']
         else:
             message = ['Encountered unknown tag \'%s\'.' % name]
 
-        if name is not None and name in expected:
-            message.append('You probably made a nesting mistake. Jinja '
-                           'is expecting this tag, but currently looking '
-                           'for %s.' % currently_looking)
-        else:
-            message.append('Jinja was looking for the following tags: '
-                           '%s.' % currently_looking)
+        if currently_looking:
+            if name is not None and name in expected:
+                message.append('You probably made a nesting mistake. Jinja '
+                               'is expecting this tag, but currently looking '
+                               'for %s.' % currently_looking)
+            else:
+                message.append('Jinja was looking for the following tags: '
+                               '%s.' % currently_looking)
 
         if self._tag_stack:
             message.append('The innermost block that needs to be '
index 93631ab165611c6a413663507a9d7a1c338da2aa..c56d510e69bc088e1bffe81f385b70b320a6210c 100644 (file)
@@ -188,6 +188,8 @@ and bar comment #}
         assert_error('{% block foo-bar-baz %}',
                      "Block names in Jinja have to be valid Python identifiers "
                      "and may not contain hypens, use an underscore instead.")
+        assert_error('{% unknown_tag %}',
+                     "Encountered unknown tag 'unknown_tag'.")
 
 
 class SyntaxTestCase(JinjaTestCase):