Patchwork [4,of,4] Make it easier to debug templater issues

login
register
mail settings
Submitter Ryan McElroy
Date June 23, 2014, 5:55 p.m.
Message ID <711c6978111f49a248a2.1403546119@nexus.gateway.2wire.net>
Download mbox | patch
Permalink /patch/5046/
State Rejected
Headers show

Comments

Ryan McElroy - June 23, 2014, 5:55 p.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@fb.com>
# Date 1402621641 25200
#      Thu Jun 12 18:07:21 2014 -0700
# Node ID 711c6978111f49a248a292d9300614bdb3ccd1be
# Parent  d2066ea5ea9943205a0dbef0c3e5cb36b8afd236
Make it easier to debug templater issues
Sean Farley - June 23, 2014, 9:05 p.m.
Ryan McElroy writes:

> # HG changeset patch
> # User Ryan McElroy <rmcelroy@fb.com>
> # Date 1402621641 25200
> #      Thu Jun 12 18:07:21 2014 -0700
> # Node ID 711c6978111f49a248a292d9300614bdb3ccd1be
> # Parent  d2066ea5ea9943205a0dbef0c3e5cb36b8afd236
> Make it easier to debug templater issues

templater: add symbol to error

This patch makes it easier to debug writing templater functions by
telling the user exactly what was sent to the templater.

> diff -r d2066ea5ea99 -r 711c6978111f mercurial/templater.py
> --- a/mercurial/templater.py	Thu Jun 12 18:02:23 2014 -0700
> +++ b/mercurial/templater.py	Thu Jun 12 18:07:21 2014 -0700
> @@ -111,7 +111,7 @@
>  def getsymbol(exp):
>      if exp[0] == 'symbol':
>          return exp[1]
> -    raise error.ParseError(_("expected a symbol"))
> +    raise error.ParseError(_("expected a symbol, got '%s'") % exp[0])
>  
>  def getlist(x):
>      if not x:
> diff -r d2066ea5ea99 -r 711c6978111f tests/test-command-template.t
> --- a/tests/test-command-template.t	Thu Jun 12 18:02:23 2014 -0700
> +++ b/tests/test-command-template.t	Thu Jun 12 18:07:21 2014 -0700
> @@ -1956,3 +1956,9 @@
>    |
>    o  line 1
>       line 2
> +
> +Test bad template with better error message
> +
> +  $ hg log -Gv -R a --template '{desc|user()}'
> +  hg: parse error: expected a symbol, got 'func'
> +  [255]

Sweet. Overall this patch series looks good and I'm glad to get some
more functionality in the template engine! Looking forward to a resend
(don't forget the --flag V2, please) addressing these small nits and
Matt's suggestion as well.

Patch

diff -r d2066ea5ea99 -r 711c6978111f mercurial/templater.py
--- a/mercurial/templater.py	Thu Jun 12 18:02:23 2014 -0700
+++ b/mercurial/templater.py	Thu Jun 12 18:07:21 2014 -0700
@@ -111,7 +111,7 @@ 
 def getsymbol(exp):
     if exp[0] == 'symbol':
         return exp[1]
-    raise error.ParseError(_("expected a symbol"))
+    raise error.ParseError(_("expected a symbol, got '%s'") % exp[0])
 
 def getlist(x):
     if not x:
diff -r d2066ea5ea99 -r 711c6978111f tests/test-command-template.t
--- a/tests/test-command-template.t	Thu Jun 12 18:02:23 2014 -0700
+++ b/tests/test-command-template.t	Thu Jun 12 18:07:21 2014 -0700
@@ -1956,3 +1956,9 @@ 
   |
   o  line 1
      line 2
+
+Test bad template with better error message
+
+  $ hg log -Gv -R a --template '{desc|user()}'
+  hg: parse error: expected a symbol, got 'func'
+  [255]