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

login
register
mail settings
Submitter Yuya Nishihara
Date March 1, 2018, 2:17 p.m.
Message ID <63188d7c6282a6851842.1519913831@mimosa>
Download mbox | patch
Permalink /patch/28551/
State Accepted
Headers show

Comments

Yuya Nishihara - March 1, 2018, 2:17 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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):