Patchwork [2,of,5] templater: add try-except stub to runmember()

login
register
mail settings
Submitter Yuya Nishihara
Date June 5, 2018, 1:18 p.m.
Message ID <e666247f5c2b95a10a84.1528204736@mimosa>
Download mbox | patch
Permalink /patch/31982/
State Accepted
Headers show

Comments

Yuya Nishihara - June 5, 2018, 1:18 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1524300196 -32400
#      Sat Apr 21 17:43:16 2018 +0900
# Node ID e666247f5c2b95a10a84123257fbe2b8af05c1e5
# Parent  f028d9f94272b971eafc60582af15d83cc9a8f4a
templater: add try-except stub to runmember()

New wrapped interface will raise ParseError if the underlying object doesn't
support dict-like lookup operation.

Patch

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -666,14 +666,16 @@  def runmember(context, mapping, data):
     if util.safehasattr(d, 'tomap'):
         lm = context.overlaymap(mapping, d.tomap())
         return runsymbol(context, lm, memb)
-    if util.safehasattr(d, 'get'):
-        return getdictitem(d, memb)
-
-    sym = findsymbolicname(darg)
-    if sym:
-        raise error.ParseError(_("keyword '%s' has no member") % sym)
-    else:
-        raise error.ParseError(_("%r has no member") % pycompat.bytestr(d))
+    try:
+        if util.safehasattr(d, 'get'):
+            return getdictitem(d, memb)
+        raise error.ParseError
+    except error.ParseError:
+        sym = findsymbolicname(darg)
+        if sym:
+            raise error.ParseError(_("keyword '%s' has no member") % sym)
+        else:
+            raise error.ParseError(_("%r has no member") % pycompat.bytestr(d))
 
 def runnegate(context, mapping, data):
     data = evalinteger(context, mapping, data,