[PATCH] util: also catch IndexError

Augie Fackler raf at durin42.com
Wed Oct 14 10:12:42 CDT 2015


On Wed, Oct 14, 2015 at 11:02:57PM +0900, Yuya Nishihara wrote:
> On Tue, 13 Oct 2015 16:08:26 -0700, Sean Farley wrote:
> > # HG changeset patch
> > # User Sean Farley <sean at farley.io>
> > # Date 1444777530 25200
> > #      Tue Oct 13 16:05:30 2015 -0700
> > # Node ID ef250ea05243630e486d04fa98d6481b25d32135
> > # Parent  a38924f7680c6b7d95e14ade999c35748c9dcafd
> > util: also catch IndexError
> >
> > This makes life so, so much easier for hgwatchman, which provides a named tuple
> > but throws an IndexError instead of a TypeError.
> >
> > diff --git a/mercurial/util.py b/mercurial/util.py
> > --- a/mercurial/util.py
> > +++ b/mercurial/util.py
> > @@ -961,11 +961,11 @@ def statmtimesec(st):
> >      to represent nanoseconds. If 'nsec' is close to 1 sec, 'int(st.st_mtime)'
> >      can be 'sec + 1'. (issue4836)
> >      """
> >      try:
> >          return st[stat.ST_MTIME]
> > -    except TypeError:
> > +    except (TypeError, IndexError):
> >          # osutil.stat doesn't allow index access and its st_mtime is int
> >          return st.st_mtime
>
> I see. The watchmanstat has only 3 elements, so st[8] can raise IndexError
> instead of returning wrong field.

Sigh. Okay, I'll go ahead and queue this then. Thanks!

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list