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

login
register
mail settings
Submitter Pulkit Goyal
Date June 2, 2017, 8:46 a.m.
Message ID <a2c4837cd74f9ff787e4.1496393168@workspace>
Download mbox | patch
Permalink /patch/21132/
State Accepted
Headers show

Comments

Pulkit Goyal - June 2, 2017, 8:46 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@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.

Patch

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: