Patchwork [4,of,9,v2] stdio: add machinery to identify failed stdout/stderr writes

login
register
mail settings
Submitter Bryan O'Sullivan
Date April 14, 2017, 4:29 a.m.
Message ID <a5aa1dfd9afed15c0cd7.1492144182@jsdf-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/20187/
State Accepted
Headers show

Comments

Bryan O'Sullivan - April 14, 2017, 4:29 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1491947652 25200
#      Tue Apr 11 14:54:12 2017 -0700
# Node ID a5aa1dfd9afed15c0cd762c4a72e5e0082ac074c
# Parent  c9e44f83b04ad81797891ba63b0fa4d1587880ea
stdio: add machinery to identify failed stdout/stderr writes

Mercurial currently fails to notice failures to write to stdout or
stderr. A correctly functioning command line tool should detect
this and exit with an error code.

To achieve this, we need a little extra plumbing, which we start
adding here.

Patch

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -122,6 +122,12 @@  class CapabilityError(RepoError):
 class RequirementError(RepoError):
     """Exception raised if .hg/requires has an unknown entry."""
 
+class StdioError(IOError):
+    """Raised if I/O to stdout or stderr fails"""
+
+    def __init__(self, err):
+        IOError.__init__(self, err.errno, err.strerror)
+
 class UnsupportedMergeRecords(Abort):
     def __init__(self, recordtypes):
         from .i18n import _