py3: hunt down str(exception) instances and use util.forcebytestr
authorAugie Fackler <augie@google.com>
Sun, 25 Feb 2018 23:08:41 -0500
changeset 36422 04c319a07c7b
parent 36421 1df7e7b8558e
child 36423 2831d918e1b4
py3: hunt down str(exception) instances and use util.forcebytestr I decided to grep around for \sstr\( and see what low-hanging fruit that showed me. This was part of that hunt. That grep pattern still has some things worth exploring. Differential Revision: https://phab.mercurial-scm.org/D2440
mercurial/commands.py
mercurial/exchange.py
mercurial/localrepo.py
mercurial/scmutil.py
mercurial/ui.py
mercurial/url.py
mercurial/util.py
--- a/mercurial/commands.py	Sun Feb 25 22:30:14 2018 -0500
+++ b/mercurial/commands.py	Sun Feb 25 23:08:41 2018 -0500
@@ -3899,7 +3899,7 @@
         try:
             return hg.updatetotally(ui, repo, checkout, brev)
         except error.UpdateAbort as inst:
-            msg = _("not updating: %s") % str(inst)
+            msg = _("not updating: %s") % util.forcebytestr(inst)
             hint = inst.hint
             raise error.UpdateAbort(msg, hint=hint)
     if modheads > 1:
--- a/mercurial/exchange.py	Sun Feb 25 22:30:14 2018 -0500
+++ b/mercurial/exchange.py	Sun Feb 25 23:08:41 2018 -0500
@@ -2149,7 +2149,8 @@
                 continue
             except error.UnsupportedBundleSpecification as e:
                 repo.ui.debug('filtering %s because unsupported bundle '
-                              'spec: %s\n' % (entry['URL'], str(e)))
+                              'spec: %s\n' % (
+                                  entry['URL'], util.forcebytestr(e)))
                 continue
         # If we don't have a spec and requested a stream clone, we don't know
         # what the entry is so don't attempt to apply it.
@@ -2254,7 +2255,8 @@
                 bundle2.applybundle(repo, cg, tr, 'clonebundles', url)
             return True
         except urlerr.httperror as e:
-            ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
+            ui.warn(_('HTTP error fetching bundle: %s\n') %
+                    util.forcebytestr(e))
         except urlerr.urlerror as e:
             ui.warn(_('error fetching bundle: %s\n') % e.reason)
 
--- a/mercurial/localrepo.py	Sun Feb 25 22:30:14 2018 -0500
+++ b/mercurial/localrepo.py	Sun Feb 25 23:08:41 2018 -0500
@@ -259,7 +259,8 @@
                     bundle2.processbundle(self._repo, b)
                 raise
         except error.PushRaced as exc:
-            raise error.ResponseError(_('push failed:'), str(exc))
+            raise error.ResponseError(_('push failed:'),
+                                      util.forcebytestr(exc))
 
     # End of _basewirecommands interface.
 
--- a/mercurial/scmutil.py	Sun Feb 25 22:30:14 2018 -0500
+++ b/mercurial/scmutil.py	Sun Feb 25 23:08:41 2018 -0500
@@ -208,7 +208,7 @@
             ui.warn(_("(%s)\n") % inst.hint)
     except ImportError as inst:
         ui.warn(_("abort: %s!\n") % inst)
-        m = str(inst).split()[-1]
+        m = util.forcebytestr(inst).split()[-1]
         if m in "mpatch bdiff".split():
             ui.warn(_("(did you forget to compile extensions?)\n"))
         elif m in "zlib".split():
--- a/mercurial/ui.py	Sun Feb 25 22:30:14 2018 -0500
+++ b/mercurial/ui.py	Sun Feb 25 23:08:41 2018 -0500
@@ -366,7 +366,7 @@
         except error.ConfigError as inst:
             if trusted:
                 raise
-            self.warn(_("ignored: %s\n") % str(inst))
+            self.warn(_("ignored: %s\n") % util.forcebytestr(inst))
 
         if self.plain():
             for k in ('debug', 'fallbackencoding', 'quiet', 'slash',
--- a/mercurial/url.py	Sun Feb 25 22:30:14 2018 -0500
+++ b/mercurial/url.py	Sun Feb 25 23:08:41 2018 -0500
@@ -449,7 +449,7 @@
             self.cookiejar = cookiejar
         except util.cookielib.LoadError as e:
             ui.warn(_('(error loading cookie file %s: %s; continuing without '
-                      'cookies)\n') % (cookiefile, str(e)))
+                      'cookies)\n') % (cookiefile, util.forcebytestr(e)))
 
     def http_request(self, request):
         if self.cookiejar:
--- a/mercurial/util.py	Sun Feb 25 22:30:14 2018 -0500
+++ b/mercurial/util.py	Sun Feb 25 23:08:41 2018 -0500
@@ -3634,7 +3634,7 @@
                 return zlib.decompress(data)
             except zlib.error as e:
                 raise error.RevlogError(_('revlog decompress error: %s') %
-                                        str(e))
+                                        forcebytestr(e))
 
     def revlogcompressor(self, opts=None):
         return self.zlibrevlogcompressor()
@@ -3860,7 +3860,7 @@
                 return ''.join(chunks)
             except Exception as e:
                 raise error.RevlogError(_('revlog decompress error: %s') %
-                                        str(e))
+                                        forcebytestr(e))
 
     def revlogcompressor(self, opts=None):
         opts = opts or {}