changeset 40662:ff8b2886c492

templater: check invalid use of list expression properly (issue5920) The error message is still cryptic, but it should be better.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 13 Nov 2018 22:15:30 +0900
parents aa588bf40a08
children fbac323eb625
files mercurial/templater.py tests/test-template-basic.t
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Tue Nov 13 18:08:55 2018 +0300
+++ b/mercurial/templater.py	Tue Nov 13 22:15:30 2018 +0900
@@ -374,9 +374,7 @@
     if not exp:
         raise error.ParseError(_("missing argument"))
     t = exp[0]
-    if t in curmethods:
-        return curmethods[t](exp, context)
-    raise error.ParseError(_("unknown method '%s'") % t)
+    return curmethods[t](exp, context)
 
 # template evaluation
 
@@ -496,6 +494,10 @@
 def buildkeyvaluepair(exp, content):
     raise error.ParseError(_("can't use a key-value pair in this context"))
 
+def buildlist(exp, context):
+    raise error.ParseError(_("can't use a list in this context"),
+                           hint=_('check place of comma and parens'))
+
 # methods to interpret function arguments or inner expressions (e.g. {_(x)})
 exprmethods = {
     "integer": lambda e, c: (templateutil.runinteger, e[1]),
@@ -508,6 +510,7 @@
     "%": buildmap,
     "func": buildfunc,
     "keyvalue": buildkeyvaluepair,
+    "list": buildlist,
     "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
     "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
     "negate": buildnegate,
--- a/tests/test-template-basic.t	Tue Nov 13 18:08:55 2018 +0300
+++ b/tests/test-template-basic.t	Tue Nov 13 22:15:30 2018 +0900
@@ -188,7 +188,8 @@
 
   $ hg debugtemplate '{" "|separate}'
   $ hg debugtemplate '{("not", "an", "argument", "list")|separate}'
-  hg: parse error: unknown method 'list'
+  hg: parse error: can't use a list in this context
+  (check place of comma and parens)
   [255]
 
 Second branch starting at nullrev: