changeset 28831:6b86ce3e3576

templater: give better error message for invalid engine type Before, KeyError was caught at changeset_templater._show(), which said "no key named '%s'" as it was intended to catch the KeyError of unknown map key. Instead, we should catch KeyError explicitly for better error indication. For those who don't know what the template engine is (read "everyone"), it is hidden extension feature that allows switching template syntax in map file. See d8c5a7f25a40 for details.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 03 Apr 2016 11:20:50 +0900
parents a5009789960c
children f5ff10f6fa6b
files mercurial/templater.py tests/test-template-engine.t
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Thu Apr 07 14:10:49 2016 -0700
+++ b/mercurial/templater.py	Sun Apr 03 11:20:50 2016 +0900
@@ -1011,8 +1011,11 @@
     def __call__(self, t, **mapping):
         ttype = t in self.map and self.map[t][0] or 'default'
         if ttype not in self.ecache:
-            self.ecache[ttype] = engines[ttype](self.load,
-                                                 self.filters, self.defaults)
+            try:
+                ecls = engines[ttype]
+            except KeyError:
+                raise error.Abort(_('invalid template engine: %s') % ttype)
+            self.ecache[ttype] = ecls(self.load, self.filters, self.defaults)
         proc = self.ecache[ttype]
 
         stream = proc.process(t, mapping)
--- a/tests/test-template-engine.t	Thu Apr 07 14:10:49 2016 -0700
+++ b/tests/test-template-engine.t	Sun Apr 03 11:20:50 2016 +0900
@@ -44,4 +44,11 @@
   0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000
   -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000
 
+invalid engine type:
+
+  $ echo 'changeset = unknown:changeset.txt' > unknownenginemap
+  $ hg log --style=./unknownenginemap
+  abort: invalid template engine: unknown
+  [255]
+
   $ cd ..