[PATCH 04 of 10 py3] scmutil: convert exception to bytes in a Py3-friendly manner

Augie Fackler raf at durin42.com
Mon May 29 10:32:26 EDT 2017


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1496000686 14400
#      Sun May 28 15:44:46 2017 -0400
# Node ID 6e1ab7424617c7c7afca7faab559507c5e816a9c
# Parent  f1ae981927af4d2d75e2a0bc58c733c9a90c085b
scmutil: convert exception to bytes in a Py3-friendly manner

As far as I can tell, the Abort instance might contain localized data,
so we need to str() then convert to bytes by hand.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -187,7 +187,10 @@ def callcatch(ui, func):
             ui.warn(_("(%s)\n") % inst.hint)
         return 1
     except error.Abort as inst:
-        ui.warn(_("abort: %s\n") % inst)
+        msg = str(inst)
+        if not isinstance(msg, bytes):
+            msg = encoding.unitolocal(msg)
+        ui.warn(_("abort: %s\n") % msg)
         if inst.hint:
             ui.warn(_("(%s)\n") % inst.hint)
     except ImportError as inst:


More information about the Mercurial-devel mailing list