[PATCH] templater: abort when a template filter raises an exception (issue2987)
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Aug 20 14:43:05 CDT 2012
On 20 août 2012, at 21:36, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Neil Kodner <neilk at fb.com>
> # Date 1345241521 25200
> # Node ID 236fd658c0fac0a4f639a455a0000d5508ee5a10
> # Parent c6f88e7f95b764e23b7e0b4353c5a6458bbc3cc4
> templater: abort when a template filter raises an exception (issue2987)
>
> diff --git a/mercurial/templater.py b/mercurial/templater.py
> --- a/mercurial/templater.py
> +++ b/mercurial/templater.py
> @@ -146,7 +146,11 @@
>
> 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) :
> + raise util.Abort(_('supplied template filter is not compatible'
> + ' with template keyword'))
>
> def buildmap(exp, context):
> func, data = compileexp(exp[1], context)
> diff --git a/tests/test-command-template.t b/tests/test-command-template.t
> --- a/tests/test-command-template.t
> +++ b/tests/test-command-template.t
> @@ -1255,6 +1255,24 @@
> abort: t:3: unmatched quotes
> [255]
>
> +Behind the scenes, this will throw TypeError
> +
> + $ hg log -l 3 --template '{date|obfuscate}\n'
> + abort: supplied template filter is not compatible with template keyword
> + [255]
> +
> +Behind the scenes, this will throw a ValueError
> +
> + $ hg log -l 3 --template 'line: {desc|shortdate}\n'
> + abort: supplied template filter is not compatible with template keyword
> + [255]
> +
> +Behind the scenes, this will throw AttributeError
> +
> + $ hg log -l 3 --template 'line: {date|escape}\n'
> + abort: supplied template filter is not compatible with template keyword
> + [255]
I think that is really should have some information about Which filter failed with which template keyword. Debugging is real pain otherwise.
Does it help the --template '{email}' too ? (user is a filter) It's a fairly common mistake around here.
--
Pierre-Yves
More information about the Mercurial-devel
mailing list