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

Yuya Nishihara yuya at tcha.org
Tue Apr 11 09:50:45 EDT 2017


On Mon, 10 Apr 2017 11:51:34 -0700, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano at fb.com>
> # Date 1490804813 25200
> #      Wed Mar 29 09:26:53 2017 -0700
> # Node ID 935d0e5af9001f3a0730e7c477dc14ae5baf4799
> # Parent  c1a8ca31d3ade6c8bb0085008bdcf30593edd78f
> 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.
> 
> diff --git a/mercurial/error.py b/mercurial/error.py
> --- a/mercurial/error.py
> +++ b/mercurial/error.py
> @@ -122,6 +122,16 @@ 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)

> +def raisestdio(err):
> +    import sys
> +    raise StdioError, StdioError(err), sys.exc_info()[2]

Perhaps raisestdio() can be moved to ui.py to avoid importing sys.


More information about the Mercurial-devel mailing list