Patchwork [V2] ui: flush stderr after printing a non-chained exception for Windows

login
register
mail settings
Submitter Matt Harbison
Date June 13, 2015, 4:46 p.m.
Message ID <a82599a17c1553204982.1434213980@Envy>
Download mbox | patch
Permalink /patch/9628/
State Accepted
Headers show

Comments

Matt Harbison - June 13, 2015, 4:46 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1434161381 14400
#      Fri Jun 12 22:09:41 2015 -0400
# Node ID a82599a17c15532049827be88e52af31c7f8b3b3
# Parent  e8075329c5fbb651508777c15cb6bc9ae33b5dff
ui: flush stderr after printing a non-chained exception for Windows

There were consistent test failures in test-bad-extension.t, because Windows
buffers stderr when redirected to a file (per the comment in ui.write_err()).
That resulted in failures like this:

  --- c:/Users/Matt/Projects/hg/tests/test-bad-extension.t
  +++ c:/Users/Matt/Projects/hg/tests/test-bad-extension.t.err
  @@ -23,11 +23,11 @@
     Traceback (most recent call last):
     Exception: bit bucket overflow
     *** failed to import extension badext2: No module named badext2
  -  Traceback (most recent call last):
  -  ImportError: No module named badext2
     hg help [-ec] [TOPIC]

     show help for a given topic or a help overview
  +  Traceback (most recent call last):
  +  ImportError: No module named badext2

   show traceback for ImportError of hgext.name if debug is set
   (note that --debug option isn't applied yet when loading extensions)

Instead of inserting another flush immediately after the print, to go along with
the one recently added prior to the print (see 3ff4b07412ad), funnel the output
through ui.write_err().  The flush prior to printing the traceback only mentions
that stdout needs to be flushed, and only stderr needs to be flushed after
printing the traceback.  ui.write_err() does both for us without needing to
redocument the quirky Windows behavior.  It will also clear any progress bar.
Yuya Nishihara - June 14, 2015, 8:50 a.m.
On Sat, 13 Jun 2015 12:46:20 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1434161381 14400
> #      Fri Jun 12 22:09:41 2015 -0400
> # Node ID a82599a17c15532049827be88e52af31c7f8b3b3
> # Parent  e8075329c5fbb651508777c15cb6bc9ae33b5dff
> ui: flush stderr after printing a non-chained exception for Windows

> -                self.flush()  # flush debug or status message
> -                traceback.print_exception(exc[0], exc[1], exc[2],
> -                                          file=self.ferr)
> +                output = traceback.format_exception(exc[0], exc[1], exc[2])
> +                self.write_err(''.join(output))

This looks good to me, thanks.
Matt Mackall - June 15, 2015, 5:39 p.m.
On Sun, 2015-06-14 at 17:50 +0900, Yuya Nishihara wrote:
> On Sat, 13 Jun 2015 12:46:20 -0400, Matt Harbison wrote:
> > # HG changeset patch
> > # User Matt Harbison <matt_harbison@yahoo.com>
> > # Date 1434161381 14400
> > #      Fri Jun 12 22:09:41 2015 -0400
> > # Node ID a82599a17c15532049827be88e52af31c7f8b3b3
> > # Parent  e8075329c5fbb651508777c15cb6bc9ae33b5dff
> > ui: flush stderr after printing a non-chained exception for Windows
> 
> > -                self.flush()  # flush debug or status message
> > -                traceback.print_exception(exc[0], exc[1], exc[2],
> > -                                          file=self.ferr)
> > +                output = traceback.format_exception(exc[0], exc[1], exc[2])
> > +                self.write_err(''.join(output))
> 
> This looks good to me, thanks.

Oops, queued this version instead.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -869,9 +869,8 @@ 
                                ''.join(causetb),
                                ''.join(exconly))
             else:
-                self.flush()  # flush debug or status message
-                traceback.print_exception(exc[0], exc[1], exc[2],
-                                          file=self.ferr)
+                output = traceback.format_exception(exc[0], exc[1], exc[2])
+                self.write_err(''.join(output))
         return self.tracebackflag or force
 
     def geteditor(self):