dispatch: handle IOError when writing to stderr
Previously, attempts to write to stderr in dispatch.run() may lead to
an exception being thrown. This would likely be handled by Python's
default exception handler, which would print the exception and exit
1.
Code in this function is already catching IOError for stdout failures
and converting to exit code 255 (-1 & 255 == 255). Why we weren't
doing the same for stderr for the sake of consistency, I don't know.
I do know that chg and hg diverged in behavior here (as the changed
test-basic.t shows).
After this commit, we catch I/O failure on stderr and change the
exit code to 255. chg and hg now behave consistently. As a bonus,
Rust hg also now passes this test.
I'm skeptical at changing the exit code due to failures this late
in the process. I think we should consider preserving the current
exit code - assuming it is non-0. And, we may want to preserve the
exit code completely if the I/O error is EPIPE (and potentially
other special error classes). There's definitely room to tweak
behavior. But for now, let's at least prevent the uncaught exception.
Differential Revision: https://phab.mercurial-scm.org/D1860
Our full contribution guidelines are in our wiki, please see:
https://www.mercurial-scm.org/wiki/ContributingChanges
If you just want a checklist to follow, you can go straight to
https://www.mercurial-scm.org/wiki/ContributingChanges#Submission_checklist
If you can't run the entire testsuite for some reason (it can be
difficult on Windows), please at least run `contrib/check-code.py` on
any files you've modified and run `python contrib/check-commit` on any
commits you've made (for example, `python contrib/check-commit
273ce12ad8f1` will report some style violations on a very old commit).