From patchwork Thu Feb 26 14:58:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [STABLE] dispatch: work around UnicodeDecodeError caused by SSLError of Python 2.7.9 From: Yuya Nishihara X-Patchwork-Id: 7834 Message-Id: <1616acd9a1e2b72b00f9.1424962690@mimosa> To: mercurial-devel@selenic.com Date: Thu, 26 Feb 2015 23:58:10 +0900 # HG changeset patch # User Yuya Nishihara # Date 1424961033 -32400 # Thu Feb 26 23:30:33 2015 +0900 # Branch stable # Node ID 1616acd9a1e2b72b00f9a00ec0c3db6397d6d972 # Parent 756c5c8331b06caba7a9b1bc1d0943323cf65b93 dispatch: work around UnicodeDecodeError caused by SSLError of Python 2.7.9 SSLError of Python 2.7.9 may keep error message in unicode. It will be wrapped by URLError(reason) at KeepAliveHandler.do_open, so inst.reason can be a unicode. https://hg.python.org/cpython/file/v2.7.9/Modules/_ssl.c#l329 diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -230,6 +230,9 @@ def _runcatch(req): except (AttributeError, IndexError): # it might be anything, for example a string reason = inst.reason + if isinstance(reason, unicode): + # SSLError of Python 2.7.9 contains a unicode + reason = reason.encode(encoding.encoding, 'replace') ui.warn(_("abort: error: %s\n") % reason) elif (util.safehasattr(inst, "args") and inst.args and inst.args[0] == errno.EPIPE):