[PATCH STABLE v2] py3: force bytestr conversion of "reason" in scmutil.callcatch()

Denis Laxalde denis at laxalde.org
Wed Dec 18 14:19:43 EST 2019


# HG changeset patch
# User Denis Laxalde <denis at laxalde.org>
# Date 1576696641 -3600
#      Wed Dec 18 20:17:21 2019 +0100
# Branch stable
# Node ID 33249635134f8c3fdcd79b1a0da15880a2f57650
# Parent  743c69b393326ab82383638c1fed669794ac0ec1
py3: force bytestr conversion of "reason" in scmutil.callcatch()

For instance, reason may be an InvalidURL as shown in added test.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -262,7 +262,7 @@ def callcatch(ui, func):
             if isinstance(reason, pycompat.unicode):
                 # SSLError of Python 2.7.9 contains a unicode
                 reason = encoding.unitolocal(reason)
-            ui.error(_(b"abort: error: %s\n") % reason)
+            ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason))
         elif (
             util.safehasattr(inst, b"args")
             and inst.args
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -614,6 +614,12 @@ No local source
   abort: repository a not found!
   [255]
 
+Invalid URL
+
+  $ hg clone http://invalid:url/a b
+  abort: error: nonnumeric port: 'url'
+  [255]
+
 No remote source
 
 #if windows



More information about the Mercurial-devel mailing list