# HG changeset patch # User Bryan O'Sullivan # Date 1345579976 25200 # Node ID 4b87d947c4e176992947256cdbe8e83cb0b8c1ea # Parent a0cf8f4cd38ba8c35132379b680ebf6d0e900e3d# Parent 099c778ceb33e26626fdc27eae362113b8894491 Merge diff -r a0cf8f4cd38b -r 4b87d947c4e1 mercurial/templater.py --- a/mercurial/templater.py Tue Aug 21 12:27:57 2012 -0500 +++ b/mercurial/templater.py Tue Aug 21 13:12:56 2012 -0700 @@ -146,7 +146,15 @@ def runfilter(context, mapping, data): func, data, filt = data - return filt(func(context, mapping, data)) + try: + return filt(func(context, mapping, data)) + except (ValueError, AttributeError, TypeError): + if isinstance(data, tuple): + dt = data[1] + else: + dt = data + raise util.Abort(_("template filter '%s' is not compatible with " + "keyword '%s'") % (filt.func_name, dt)) def buildmap(exp, context): func, data = compileexp(exp[1], context) diff -r a0cf8f4cd38b -r 4b87d947c4e1 tests/test-command-template.t --- a/tests/test-command-template.t Tue Aug 21 12:27:57 2012 -0500 +++ b/tests/test-command-template.t Tue Aug 21 13:12:56 2012 -0700 @@ -1363,6 +1363,30 @@ abort: t:3: unmatched quotes [255] +Behind the scenes, this will throw TypeError + + $ hg log -l 3 --template '{date|obfuscate}\n' + abort: Template filter 'obfuscate' is not compatible with keyword 'date' + [255] + +Behind the scenes, this will throw a ValueError + + $ hg log -l 3 --template 'line: {desc|shortdate}\n' + abort: Template filter 'shortdate' is not compatible with keyword 'desc' + [255] + +Behind the scenes, this will throw AttributeError + + $ hg log -l 3 --template 'line: {date|escape}\n' + abort: Template filter 'escape' is not compatible with keyword 'date' + [255] + +Behind the scenes, this will throw ValueError + + $ hg tip --template '{author|email|date}\n' + abort: Template filter 'datefilter' is not compatible with keyword 'author' + [255] + $ cd ..