templatefuncs: show hint if extdata source is evaluated to empty (issue5843)
authorYuya Nishihara <yuya@tcha.org>
Thu, 19 Apr 2018 21:00:12 +0900
changeset 37931 faa41fd282d1
parent 37930 892592475094
child 37932 bf6bb710b40f
templatefuncs: show hint if extdata source is evaluated to empty (issue5843)
mercurial/templatefuncs.py
tests/test-extdata.t
--- a/mercurial/templatefuncs.py	Fri May 04 21:31:34 2018 -0700
+++ b/mercurial/templatefuncs.py	Thu Apr 19 21:00:12 2018 +0900
@@ -113,6 +113,13 @@
         raise error.ParseError(_('extdata expects one argument'))
 
     source = evalstring(context, mapping, args['source'])
+    if not source:
+        sym = templateutil.findsymbolicname(args['source'])
+        if sym:
+            raise error.ParseError(_('empty data source specified'),
+                                   hint=_("did you mean extdata('%s')?") % sym)
+        else:
+            raise error.ParseError(_('empty data source specified'))
     cache = context.resource(mapping, 'cache').setdefault('extdata', {})
     ctx = context.resource(mapping, 'ctx')
     if source in cache:
--- a/tests/test-extdata.t	Fri May 04 21:31:34 2018 -0700
+++ b/tests/test-extdata.t	Thu Apr 19 21:00:12 2018 +0900
@@ -82,6 +82,13 @@
   $ hg log -T "{extdata('unknown')}\n"
   abort: unknown extdata source 'unknown'
   [255]
+  $ hg log -T "{extdata(unknown)}\n"
+  hg: parse error: empty data source specified
+  (did you mean extdata('unknown')?)
+  [255]
+  $ hg log -T "{extdata('{unknown}')}\n"
+  hg: parse error: empty data source specified
+  [255]
 
 we don't fix up relative file URLs, but we do run shell commands in repo root