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

login
register
mail settings
Submitter Denis Laxalde
Date Dec. 18, 2019, 7:19 p.m.
Message ID <33249635134f8c3fdcd7.1576696783@marimba>
Download mbox | patch
Permalink /patch/43976/
State Accepted
Headers show

Comments

Denis Laxalde - Dec. 18, 2019, 7:19 p.m.
# HG changeset patch
# User Denis Laxalde <denis@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.
Yuya Nishihara - Dec. 19, 2019, 12:21 p.m.
On Wed, 18 Dec 2019 20:19:43 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis@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()

Queued for stable, thanks.

Patch

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