Mercurial > hg
changeset 31960:71dcd4a4fa2f
stdio: catch StdioError in dispatch.run and clean up appropriately
We attempt to report what went wrong, and more importantly exit the
program with an error code.
(The exception we catch is not yet raised anywhere in the code.)
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Tue, 11 Apr 2017 14:54:12 -0700 |
parents | b445a3f00528 |
children | db823e38a61c |
files | mercurial/dispatch.py |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dispatch.py Tue Apr 11 14:54:12 2017 -0700 +++ b/mercurial/dispatch.py Tue Apr 11 14:54:12 2017 -0700 @@ -77,7 +77,22 @@ def run(): "run the command in sys.argv" - sys.exit((dispatch(request(pycompat.sysargv[1:])) or 0) & 255) + req = request(pycompat.sysargv[1:]) + err = None + try: + status = (dispatch(req) or 0) & 255 + except error.StdioError as err: + status = -1 + if util.safehasattr(req.ui, 'fout'): + try: + req.ui.fout.close() + except IOError as err: + status = -1 + if util.safehasattr(req.ui, 'ferr'): + if err is not None and err.errno != errno.EPIPE: + req.ui.ferr.write('abort: %s\n' % err.strerror) + req.ui.ferr.close() + sys.exit(status & 255) def _getsimilar(symbols, value): sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio()