Patchwork [3,of,5] py3: fix some unicode madness in global exception catcher

login
register
mail settings
Submitter Yuya Nishihara
Date March 3, 2018, 5:12 p.m.
Message ID <eb6c1453a714d61c7101.1520097151@mimosa>
Download mbox | patch
Permalink /patch/28792/
State Accepted
Headers show

Comments

Yuya Nishihara - March 3, 2018, 5:12 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520089356 18000
#      Sat Mar 03 10:02:36 2018 -0500
# Node ID eb6c1453a714d61c7101a3c0f360cb8f661d827c
# Parent  e246d075d3d8b115b0cc40c7c99de94f40a17f15
py3: fix some unicode madness in global exception catcher

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -496,7 +496,7 @@  class cmdalias(object):
             args = pycompat.shlexsplit(self.definition)
         except ValueError as inst:
             self.badalias = (_("error in definition for alias '%s': %s")
-                             % (self.name, inst))
+                             % (self.name, util.forcebytestr(inst)))
             return
         earlyopts, args = _earlysplitopts(args)
         if earlyopts:
@@ -623,7 +623,7 @@  def _parse(ui, args):
     try:
         args = fancyopts.fancyopts(args, commands.globalopts, options)
     except getopt.GetoptError as inst:
-        raise error.CommandError(None, inst)
+        raise error.CommandError(None, util.forcebytestr(inst))
 
     if args:
         cmd, args = args[0], args[1:]
@@ -647,7 +647,7 @@  def _parse(ui, args):
     try:
         args = fancyopts.fancyopts(args, c, cmdoptions, gnu=True)
     except getopt.GetoptError as inst:
-        raise error.CommandError(cmd, inst)
+        raise error.CommandError(cmd, util.forcebytestr(inst))
 
     # separate global options back out
     for o in commands.globalopts:
@@ -672,7 +672,8 @@  def _parseconfig(ui, config):
             configs.append((section, name, value))
         except (IndexError, ValueError):
             raise error.Abort(_('malformed --config option: %r '
-                               '(use --config section.name=value)') % cfg)
+                                '(use --config section.name=value)')
+                              % pycompat.bytestr(cfg))
 
     return configs
 
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -162,13 +162,14 @@  def callcatch(ui, func):
             reason = _('timed out waiting for lock held by %r') % inst.locker
         else:
             reason = _('lock held by %r') % inst.locker
-        ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
+        ui.warn(_("abort: %s: %s\n")
+                % (inst.desc or encoding.strtolocal(inst.filename), reason))
         if not inst.locker:
             ui.warn(_("(lock might be very busy)\n"))
     except error.LockUnavailable as inst:
         ui.warn(_("abort: could not lock %s: %s\n") %
-               (inst.desc or inst.filename,
-                encoding.strtolocal(inst.strerror)))
+                (inst.desc or encoding.strtolocal(inst.filename),
+                 encoding.strtolocal(inst.strerror)))
     except error.OutOfBandError as inst:
         if inst.args:
             msg = _("abort: remote error:\n")
@@ -207,7 +208,7 @@  def callcatch(ui, func):
         if inst.hint:
             ui.warn(_("(%s)\n") % inst.hint)
     except ImportError as inst:
-        ui.warn(_("abort: %s!\n") % inst)
+        ui.warn(_("abort: %s!\n") % util.forcebytestr(inst))
         m = util.forcebytestr(inst).split()[-1]
         if m in "mpatch bdiff".split():
             ui.warn(_("(did you forget to compile extensions?)\n"))
@@ -232,7 +233,8 @@  def callcatch(ui, func):
         elif getattr(inst, "strerror", None):
             if getattr(inst, "filename", None):
                 ui.warn(_("abort: %s: %s\n") % (
-                    encoding.strtolocal(inst.strerror), inst.filename))
+                    encoding.strtolocal(inst.strerror),
+                    encoding.strtolocal(inst.filename)))
             else:
                 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
         else:
@@ -240,7 +242,8 @@  def callcatch(ui, func):
     except OSError as inst:
         if getattr(inst, "filename", None) is not None:
             ui.warn(_("abort: %s: '%s'\n") % (
-                encoding.strtolocal(inst.strerror), inst.filename))
+                encoding.strtolocal(inst.strerror),
+                encoding.strtolocal(inst.filename)))
         else:
             ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
     except MemoryError:
@@ -250,7 +253,7 @@  def callcatch(ui, func):
         # Just in case catch this and and pass exit code to caller.
         return inst.code
     except socket.error as inst:
-        ui.warn(_("abort: %s\n") % inst.args[-1])
+        ui.warn(_("abort: %s\n") % util.forcebytestr(inst.args[-1]))
 
     return -1