Mercurial > public > mercurial-scm > hg
comparison mercurial/templateutil.py @ 37226:920589f52be9
templater: attach hint to input-type error of runfilter()
Tests will be added by the next patch.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 20 Mar 2018 22:57:36 +0900 |
parents | e70a90a72b80 |
children | 9bcf096a2da2 |
comparison
equal
deleted
inserted
replaced
37225:e70a90a72b80 | 37226:920589f52be9 |
---|---|
421 thing = evalrawexp(context, mapping, arg) | 421 thing = evalrawexp(context, mapping, arg) |
422 try: | 422 try: |
423 thing = unwrapastype(thing, getattr(filt, '_intype', None)) | 423 thing = unwrapastype(thing, getattr(filt, '_intype', None)) |
424 return filt(thing) | 424 return filt(thing) |
425 except (ValueError, AttributeError, TypeError): | 425 except (ValueError, AttributeError, TypeError): |
426 sym = findsymbolicname(arg) | 426 raise error.Abort(_formatfiltererror(arg, filt)) |
427 if sym: | 427 except error.ParseError as e: |
428 msg = (_("template filter '%s' is not compatible with keyword '%s'") | 428 raise error.ParseError(bytes(e), hint=_formatfiltererror(arg, filt)) |
429 % (pycompat.sysbytes(filt.__name__), sym)) | 429 |
430 else: | 430 def _formatfiltererror(arg, filt): |
431 msg = (_("incompatible use of template filter '%s'") | 431 fn = pycompat.sysbytes(filt.__name__) |
432 % pycompat.sysbytes(filt.__name__)) | 432 sym = findsymbolicname(arg) |
433 raise error.Abort(msg) | 433 if not sym: |
434 return _("incompatible use of template filter '%s'") % fn | |
435 return (_("template filter '%s' is not compatible with keyword '%s'") | |
436 % (fn, sym)) | |
434 | 437 |
435 def runmap(context, mapping, data): | 438 def runmap(context, mapping, data): |
436 darg, targ = data | 439 darg, targ = data |
437 d = evalrawexp(context, mapping, darg) | 440 d = evalrawexp(context, mapping, darg) |
438 if util.safehasattr(d, 'itermaps'): | 441 if util.safehasattr(d, 'itermaps'): |