[PATCH 8 of 9] stdio: raise StdioError if something goes wrong in ui.flush

Bryan O'Sullivan bos at serpentine.com
Mon Apr 10 14:51:38 EDT 2017


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1490915085 25200
#      Thu Mar 30 16:04:45 2017 -0700
# Node ID fd3b4caa7c4fca4c7df1bdf9110ca0b8f56b1677
# Parent  fdac23ea683f6b2b76885e3aafb9a6bdb53218ab
stdio: raise StdioError if something goes wrong in ui.flush

The prior code used to ignore all errors, which was intended to
deal with a decade-old problem with writing to broken pipes on
Windows.

However, that code inadvertantly went a lot further, making it
impossible to detect *all* I/O errors on stdio ... but only sometimes.

What actually happened was that if Mercurial wrote less than a stdio
buffer's worth of output (the overwhelmingly common case for most
commands), any error that occurred would get swallowed here.  But
if the buffering strategy changed, an unhandled IOError could be
raised from any number of other locations.

Because we now have a top-level StdioError handler, and ui._write
and ui._write_err (and now flush!) will raise that exception, we
have one rational place to detect and handle these errors.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -804,10 +804,15 @@ class ui(object):
         # opencode timeblockedsection because this is a critical path
         starttime = util.timer()
         try:
-            try: self.fout.flush()
-            except (IOError, ValueError): pass
-            try: self.ferr.flush()
-            except (IOError, ValueError): pass
+            try:
+                self.fout.flush()
+            except IOError as err:
+                error.raisestdio(err)
+            finally:
+                try:
+                    self.ferr.flush()
+                except IOError as err:
+                    error.raisestdio(err)
         finally:
             self._blockedtimes['stdio_blocked'] += \
                 (util.timer() - starttime) * 1000


More information about the Mercurial-devel mailing list