Patchwork [5,of,6,py3] ui: fix ui.traceback on Python 3

login
register
mail settings
Submitter Augie Fackler
Date March 3, 2017, 7:30 p.m.
Message ID <168a2acc512f0dbcc9d1.1488569408@imladris.local>
Download mbox | patch
Permalink /patch/18898/
State Accepted
Headers show

Comments

Augie Fackler - March 3, 2017, 7:30 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1488568154 18000
#      Fri Mar 03 14:09:14 2017 -0500
# Node ID 168a2acc512f0dbcc9d1469ae97ea4226fc18243
# Parent  224bce12f19ec6fb7ab1563797d81e902121dcb6
ui: fix ui.traceback on Python 3
Yuya Nishihara - March 5, 2017, 6:35 a.m.
On Fri, 03 Mar 2017 14:30:08 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1488568154 18000
> #      Fri Mar 03 14:09:14 2017 -0500
> # Node ID 168a2acc512f0dbcc9d1469ae97ea4226fc18243
> # Parent  224bce12f19ec6fb7ab1563797d81e902121dcb6
> ui: fix ui.traceback on Python 3
> 
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -1335,7 +1335,9 @@ class ui(object):
>                                 ''.join(exconly))
>              else:
>                  output = traceback.format_exception(exc[0], exc[1], exc[2])
> -                self.write_err(''.join(output))
> +                data = u''.join(output).encode(

output may contain non-ascii bytes on Python 2, which causes
UnicodeDecodeError.

> +                    encoding.encoding.decode('latin1'))

And this could raise UnicodeEncodeError on Python 3. The easiest workaround
would be setting errors='replace'.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1335,7 +1335,9 @@  class ui(object):
                                ''.join(exconly))
             else:
                 output = traceback.format_exception(exc[0], exc[1], exc[2])
-                self.write_err(''.join(output))
+                data = u''.join(output).encode(
+                    encoding.encoding.decode('latin1'))
+                self.write_err(data)
         return self.tracebackflag or force
 
     def geteditor(self):