[PATCH 3 of 6 V2] py3: convert exception to bytes to pass into ui.warn()

Pulkit Goyal 7895pulkit at gmail.com
Fri Jun 2 04:46:08 EDT 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1496379921 -19800
#      Fri Jun 02 10:35:21 2017 +0530
# Node ID a2c4837cd74f9ff787e4f085a7b216075fcd233e
# Parent  9c2175e859f45ed46936469a759e6c8b9004a22a
py3: convert exception to bytes to pass into ui.warn()

Here encoding.strtolocal() is used because exc maybe an IOError which could
contain a valid non-ascii unicode.

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -13,6 +13,7 @@
 from .i18n import _
 from . import (
     demandimport,
+    encoding,
     error,
     extensions,
     pycompat,
@@ -97,7 +98,7 @@
                          (hname, exc.args[0]))
         else:
             ui.warn(_('error: %s hook raised an exception: '
-                           '%s\n') % (hname, exc))
+                           '%s\n') % (hname, encoding.strtolocal(str(exc))))
         if throw:
             raise
         if not ui.tracebackflag:


More information about the Mercurial-devel mailing list