[PATCH 4 of 8] py3: move between bytes and unicode when re-raising IOError

Yuya Nishihara yuya at tcha.org
Thu Mar 1 09:17:11 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1519904826 18000
#      Thu Mar 01 06:47:06 2018 -0500
# Node ID 63188d7c6282a68518421ef7f60c85b312ffec3b
# Parent  7002f11e42c57d80e3e001b48e956d0f9a94b758
py3: move between bytes and unicode when re-raising IOError

IOError is a Python exception, which argument must be a system string.

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -1537,8 +1537,9 @@ class templater(object):
                 raise TemplateNotFound(_('"%s" not in template map') %
                                        inst.args[0])
             except IOError as inst:
-                raise IOError(inst.args[0], _('template file %s: %s') %
-                              (self.map[t][1], inst.args[1]))
+                reason = (_('template file %s: %s')
+                          % (self.map[t][1], util.forcebytestr(inst.args[1])))
+                raise IOError(inst.args[0], encoding.strfromlocal(reason))
         return self.cache[t]
 
     def render(self, mapping):


More information about the Mercurial-devel mailing list