From patchwork Sat Mar 31 01:49:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [06,of,11] templater: attach hint to input-type error of runfilter() From: Yuya Nishihara X-Patchwork-Id: 30043 Message-Id: <044cf5cbae04306dc219.1522460974@mimosa> To: mercurial-devel@mercurial-scm.org Date: Sat, 31 Mar 2018 10:49:34 +0900 # HG changeset patch # User Yuya Nishihara # Date 1521554256 -32400 # Tue Mar 20 22:57:36 2018 +0900 # Node ID 044cf5cbae04306dc21919b1dbb461a1f01b3a2e # Parent 5195b8b4c84633ed4529a0c5430c3b04e88f6898 templater: attach hint to input-type error of runfilter() Tests will be added by the next patch. diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py --- a/mercurial/templateutil.py +++ b/mercurial/templateutil.py @@ -423,14 +423,17 @@ def runfilter(context, mapping, data): thing = unwrapastype(thing, getattr(filt, '_intype', None)) return filt(thing) except (ValueError, AttributeError, TypeError): - sym = findsymbolicname(arg) - if sym: - msg = (_("template filter '%s' is not compatible with keyword '%s'") - % (pycompat.sysbytes(filt.__name__), sym)) - else: - msg = (_("incompatible use of template filter '%s'") - % pycompat.sysbytes(filt.__name__)) - raise error.Abort(msg) + raise error.Abort(_formatfiltererror(arg, filt)) + except error.ParseError as e: + raise error.ParseError(bytes(e), hint=_formatfiltererror(arg, filt)) + +def _formatfiltererror(arg, filt): + fn = pycompat.sysbytes(filt.__name__) + sym = findsymbolicname(arg) + if not sym: + return _("incompatible use of template filter '%s'") % fn + return (_("template filter '%s' is not compatible with keyword '%s'") + % (fn, sym)) def runmap(context, mapping, data): darg, targ = data