Mercurial > hg
changeset 38271:4b0f39e7406e
templater: show slightly better hint on map operation error
It was super hard to find where the templater went wrong if a keyword was
evaluated to '' or None.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 08 Jun 2018 20:57:54 +0900 |
parents | 630c62804383 |
children | 354fad8697fd |
files | mercurial/templateutil.py tests/test-command-template.t |
diffstat | 2 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templateutil.py Wed Mar 21 12:28:12 2018 +0900 +++ b/mercurial/templateutil.py Fri Jun 08 20:57:54 2018 +0900 @@ -753,14 +753,22 @@ lm['index'] = i yield lm -def _applymap(context, mapping, d, targ): - for lm in _iteroverlaymaps(context, mapping, d.itermaps(context)): +def _applymap(context, mapping, d, darg, targ): + try: + diter = d.itermaps(context) + except error.ParseError as err: + sym = findsymbolicname(darg) + if not sym: + raise + hint = _("keyword '%s' does not support map operation") % sym + raise error.ParseError(bytes(err), hint=hint) + for lm in _iteroverlaymaps(context, mapping, diter): yield evalrawexp(context, lm, targ) def runmap(context, mapping, data): darg, targ = data d = evalwrapped(context, mapping, darg) - return mappedgenerator(_applymap, args=(mapping, d, targ)) + return mappedgenerator(_applymap, args=(mapping, d, darg, targ)) def runmember(context, mapping, data): darg, memb = data
--- a/tests/test-command-template.t Wed Mar 21 12:28:12 2018 +0900 +++ b/tests/test-command-template.t Fri Jun 08 20:57:54 2018 +0900 @@ -3213,6 +3213,7 @@ $ hg log -R latesttag -r tip -T '{rev % "a"}\n' hg: parse error: 11 is not iterable of mappings + (keyword 'rev' does not support map operation) [255] $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n' hg: parse error: None is not iterable of mappings