[PATCH STABLE] fancyopts: don't show a traceback on invalid integer values

Pierre-Yves David pierre-yves.david at logilab.fr
Mon Oct 8 08:47:53 CDT 2012


LGTM

On Mon, Oct 08, 2012 at 03:38:51PM +0200, Idan Kamara wrote:
> # HG changeset patch
> # User Idan Kamara <idankk86 at gmail.com>
> # Date 1349703316 -7200
> # Branch stable
> # Node ID 6cd5ee6df3c463d2025cf17158c4ad8ca484d00f
> # Parent  67f7906491d804423d16cb151e7add017ca1138d
> fancyopts: don't show a traceback on invalid integer values
> 
> diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py
> --- a/mercurial/fancyopts.py
> +++ b/mercurial/fancyopts.py
> @@ -5,7 +5,8 @@
>  # This software may be used and distributed according to the terms of the
>  # GNU General Public License version 2 or any later version.
>  
> -import getopt
> +import getopt, util
> +from i18n import _
>  
>  def gnugetopt(args, options, longoptions):
>      """Parse options mostly like getopt.gnu_getopt.
> @@ -105,7 +106,11 @@
>          if t is type(fancyopts):
>              state[name] = defmap[name](val)
>          elif t is type(1):
> -            state[name] = int(val)
> +            try:
> +                state[name] = int(val)
> +            except ValueError:
> +                raise util.Abort(_('invalid value %r for option %s, '
> +                                   'expected int') % (val, opt))
>          elif t is type(''):
>              state[name] = val
>          elif t is type([]):
> diff --git a/tests/test-import.t b/tests/test-import.t
> --- a/tests/test-import.t
> +++ b/tests/test-import.t
> @@ -602,6 +602,9 @@
>    $ echo a > a
>    $ hg ci -Am t
>    adding a
> +  $ hg import -p foo
> +  abort: invalid value 'foo' for option -p, expected int
> +  [255]
>    $ hg import -p0 - << EOF
>    > foobar
>    > --- a	Sat Apr 12 22:43:58 2008 -0400
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

-- 
Pierre-Yves David

http://www.logilab.fr/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20121008/2bb69acc/attachment.pgp>


More information about the Mercurial-devel mailing list