Mercurial > hg
comparison mercurial/dispatch.py @ 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 | de5c9d0e02ea |
children | 0fb78cb90ca7 |
comparison
equal
deleted
inserted
replaced
31959:b445a3f00528 | 31960:71dcd4a4fa2f |
---|---|
75 if exc is not None: | 75 if exc is not None: |
76 raise exc | 76 raise exc |
77 | 77 |
78 def run(): | 78 def run(): |
79 "run the command in sys.argv" | 79 "run the command in sys.argv" |
80 sys.exit((dispatch(request(pycompat.sysargv[1:])) or 0) & 255) | 80 req = request(pycompat.sysargv[1:]) |
81 err = None | |
82 try: | |
83 status = (dispatch(req) or 0) & 255 | |
84 except error.StdioError as err: | |
85 status = -1 | |
86 if util.safehasattr(req.ui, 'fout'): | |
87 try: | |
88 req.ui.fout.close() | |
89 except IOError as err: | |
90 status = -1 | |
91 if util.safehasattr(req.ui, 'ferr'): | |
92 if err is not None and err.errno != errno.EPIPE: | |
93 req.ui.ferr.write('abort: %s\n' % err.strerror) | |
94 req.ui.ferr.close() | |
95 sys.exit(status & 255) | |
81 | 96 |
82 def _getsimilar(symbols, value): | 97 def _getsimilar(symbols, value): |
83 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() | 98 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() |
84 # The cutoff for similarity here is pretty arbitrary. It should | 99 # The cutoff for similarity here is pretty arbitrary. It should |
85 # probably be investigated and tweaked. | 100 # probably be investigated and tweaked. |