changeset 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
files mercurial/templateutil.py
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templateutil.py	Sun Mar 18 15:58:22 2018 +0900
+++ b/mercurial/templateutil.py	Tue Mar 20 22:57:36 2018 +0900
@@ -423,14 +423,17 @@
         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