##// END OF EJS Templates
templater: find keyword name more thoroughly on filtering error...
Yuya Nishihara -
r31927:2abc556d default
parent child Browse files
Show More
@@ -284,6 +284,18 b' def gettemplate(exp, context):'
284 return context._load(exp[1])
284 return context._load(exp[1])
285 raise error.ParseError(_("expected template specifier"))
285 raise error.ParseError(_("expected template specifier"))
286
286
287 def findsymbolicname(arg):
288 """Find symbolic name for the given compiled expression; returns None
289 if nothing found reliably"""
290 while True:
291 func, data = arg
292 if func is runsymbol:
293 return data
294 elif func is runfilter:
295 arg = data[0]
296 else:
297 return None
298
287 def evalfuncarg(context, mapping, arg):
299 def evalfuncarg(context, mapping, arg):
288 func, data = arg
300 func, data = arg
289 # func() may return string, generator of strings or arbitrary object such
301 # func() may return string, generator of strings or arbitrary object such
@@ -387,12 +399,13 b' def runfilter(context, mapping, data):'
387 try:
399 try:
388 return filt(thing)
400 return filt(thing)
389 except (ValueError, AttributeError, TypeError):
401 except (ValueError, AttributeError, TypeError):
390 if isinstance(arg[1], tuple):
402 sym = findsymbolicname(arg)
391 dt = arg[1][1]
403 if sym:
404 msg = (_("template filter '%s' is not compatible with keyword '%s'")
405 % (filt.func_name, sym))
392 else:
406 else:
393 dt = arg[1]
407 msg = _("incompatible use of template filter '%s'") % filt.func_name
394 raise error.Abort(_("template filter '%s' is not compatible with "
408 raise error.Abort(msg)
395 "keyword '%s'") % (filt.func_name, dt))
396
409
397 def buildmap(exp, context):
410 def buildmap(exp, context):
398 func, data = compileexp(exp[1], context, methods)
411 func, data = compileexp(exp[1], context, methods)
@@ -2684,6 +2684,14 b' Behind the scenes, this will throw Value'
2684 hg: parse error: date expects a date information
2684 hg: parse error: date expects a date information
2685 [255]
2685 [255]
2686
2686
2687 $ hg tip -T '{author|email|shortdate}\n'
2688 abort: template filter 'shortdate' is not compatible with keyword 'author'
2689 [255]
2690
2691 $ hg tip -T '{get(extras, "branch")|shortdate}\n'
2692 abort: incompatible use of template filter 'shortdate'
2693 [255]
2694
2687 Error in nested template:
2695 Error in nested template:
2688
2696
2689 $ hg log -T '{"date'
2697 $ hg log -T '{"date'
General Comments 0
You need to be logged in to leave comments. Login now