Patchwork revsetbenchmark: handle exception case

login
register
mail settings
Submitter Durham Goode
Date Feb. 10, 2016, 11:22 p.m.
Message ID <c791244507faabf86b1f.1455146564@dev8486.prn1.facebook.com>
Download mbox | patch
Permalink /patch/13107/
State Accepted
Headers show

Comments

Durham Goode - Feb. 10, 2016, 11:22 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1455136765 28800
#      Wed Feb 10 12:39:25 2016 -0800
# Node ID c791244507faabf86b1fd71746ec5b3d0364ed7d
# Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
revsetbenchmark: handle exception case

If the revset being benchmarked has an exception, the handling code was
encountering an error because the exception did not always have an "output"
attribute (I think it's a python 2.7 thing).
Sean Farley - Feb. 10, 2016, 11:38 p.m.
Durham Goode <durham@fb.com> writes:

> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1455136765 28800
> #      Wed Feb 10 12:39:25 2016 -0800
> # Node ID c791244507faabf86b1fd71746ec5b3d0364ed7d
> # Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
> revsetbenchmark: handle exception case
>
> If the revset being benchmarked has an exception, the handling code was
> encountering an error because the exception did not always have an "output"
> attribute (I think it's a python 2.7 thing).

Sure, seems fine.
Pierre-Yves David - Feb. 12, 2016, 1:31 p.m.
On 02/10/2016 11:22 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1455136765 28800
> #      Wed Feb 10 12:39:25 2016 -0800
> # Node ID c791244507faabf86b1fd71746ec5b3d0364ed7d
> # Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
> revsetbenchmark: handle exception case
>
> If the revset being benchmarked has an exception, the handling code was
> encountering an error because the exception did not always have an "output"
> attribute (I think it's a python 2.7 thing).
>
> diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
> --- a/contrib/revsetbenchmarks.py
> +++ b/contrib/revsetbenchmarks.py
> @@ -63,7 +63,7 @@ def perf(revset, target=None, contexts=F
>           return parseoutput(output)
>       except CalledProcessError as exc:
>           print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd
> -        if exc.output is None:
> +        if getattr(exc, 'output', None) is None:
>               print >> sys.stderr, '(no output)'
>           else:
>               print >> sys.stderr, exc.output

I've added a small comment pointing at the fact we use getattr because 
pre 2.7 python and the result is pushed to the clowncopter.

Thanks

Patch

diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py
+++ b/contrib/revsetbenchmarks.py
@@ -63,7 +63,7 @@  def perf(revset, target=None, contexts=F
         return parseoutput(output)
     except CalledProcessError as exc:
         print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd
-        if exc.output is None:
+        if getattr(exc, 'output', None) is None:
             print >> sys.stderr, '(no output)'
         else:
             print >> sys.stderr, exc.output