]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Better error messages for some undefines. This fixes #575 637/head
authorArmin Ronacher <armin.ronacher@active-4.com>
Fri, 6 Jan 2017 11:53:31 +0000 (12:53 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Fri, 6 Jan 2017 11:53:31 +0000 (12:53 +0100)
CHANGES
jinja2/environment.py

diff --git a/CHANGES b/CHANGES
index 2356fc95dcb6b13c8d059747d02d1e37ae632bc2..7c072afcdd4fa8967ade163ebc7cb6ef573ef807 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,8 @@ Version 2.9
 - Restored behavior of Cycler for Python 3 users.
 - Subtraction now follows the same behavior as other operators on undefined
   values.
+- `map` and friends will now give better error messages if you forgot to
+  quote the parameter.
 
 Version 2.8.2
 -------------
index cfa7ff1e1bd906fff64f6c444e89607d36834010..0b5f957d48f49a31cef30820239d01e3f16cb56b 100644 (file)
@@ -88,6 +88,16 @@ def load_extensions(environment, extensions):
     return result
 
 
+def fail_for_missing_callable(string, name):
+    msg = string % name
+    if isinstance(name, Undefined):
+        try:
+            name._fail_with_undefined_error()
+        except Exception as e:
+            msg = '%s (%s; did you forget to quote the callable name?)' % (msg, e)
+    raise TemplateRuntimeError(msg)
+
+
 def _environment_sanity_check(environment):
     """Perform a sanity check on the environment."""
     assert issubclass(environment.undefined, Undefined), 'undefined must ' \
@@ -439,7 +449,7 @@ class Environment(object):
         """
         func = self.filters.get(name)
         if func is None:
-            raise TemplateRuntimeError('no filter named %r' % name)
+            fail_for_missing_callable('no filter named %r', name)
         args = [value] + list(args or ())
         if getattr(func, 'contextfilter', False):
             if context is None:
@@ -464,7 +474,7 @@ class Environment(object):
         """
         func = self.tests.get(name)
         if func is None:
-            raise TemplateRuntimeError('no test named %r' % name)
+            fail_for_missing_callable('no test named %r', name)
         return func(value, *(args or ()), **(kwargs or {}))
 
     @internalcode