Patchwork templatefuncs: show hint if extdata source is evaluated to empty (issue5843)

login
register
mail settings
Submitter Yuya Nishihara
Date May 7, 2018, 1:17 p.m.
Message ID <a9f180ee5a2a3a0f1995.1525699049@mimosa>
Download mbox | patch
Permalink /patch/31305/
State Accepted
Headers show

Comments

Yuya Nishihara - May 7, 2018, 1:17 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1524139212 -32400
#      Thu Apr 19 21:00:12 2018 +0900
# Node ID a9f180ee5a2a3a0f199502643c19b05229320a56
# Parent  fe85fe4b7cd677ea2267c002a8534bc079a82d51
templatefuncs: show hint if extdata source is evaluated to empty (issue5843)

Patch

diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -112,6 +112,13 @@  def extdata(context, mapping, args):
         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:
diff --git a/tests/test-extdata.t b/tests/test-extdata.t
--- a/tests/test-extdata.t
+++ b/tests/test-extdata.t
@@ -82,6 +82,13 @@  test bad extdata() template source
   $ 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