Patchwork [2,of,2,v2,py3] dispatch: convert exception payload to bytes more carefully

login
register
mail settings
Submitter Augie Fackler
Date May 31, 2017, 7:15 p.m.
Message ID <717c41aef8adcaf71edd.1496258144@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/21093/
State Accepted
Headers show

Comments

Augie Fackler - May 31, 2017, 7:15 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1496000820 14400
#      Sun May 28 15:47:00 2017 -0400
# Node ID 717c41aef8adcaf71eddb1d2256ca604db5ea9fe
# Parent  21fdfbb91fa693787db38decfc21962d1e004e28
dispatch: convert exception payload to bytes more carefully

We were previously depending on str() doing something reasonable here,
and we can't depend on the objects in question supporting __bytes__,
so we work around the lack of direct bytes formatting.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -319,7 +319,8 @@  def _callcatch(ui, func):
     except error.CommandError as inst:
         if inst.args[0]:
             ui.pager('help')
-            ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
+            msgbytes = pycompat.bytestr(inst.args[1])
+            ui.warn(_("hg %s: %s\n") % (inst.args[0], msgbytes))
             commands.help_(ui, inst.args[0], full=False, command=True)
         else:
             ui.pager('help')