Patchwork [8,of,8] py3: create built in exceptions with str type messages in win32.py

login
register
mail settings
Submitter Matt Harbison
Date Sept. 22, 2018, 3:28 p.m.
Message ID <ca417c9464d378661e9e.1537630124@Envy>
Download mbox | patch
Permalink /patch/34922/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 22, 2018, 3:28 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1537580667 14400
#      Fri Sep 21 21:44:27 2018 -0400
# Node ID ca417c9464d378661e9e962be1447647006297f3
# Parent  f6dbc0131f506de7f3484946b2e1d90c2a087d74
py3: create built in exceptions with str type messages in win32.py

I hit an IOError in unlink() in test-pathconflicts-basic.t, that then crashed as
it was handled:

    File "mercurial\dispatch.py", line 359, in _runcatch
      return _callcatch(ui, _runcatchfunc)
    File "mercurial\dispatch.py", line 367, in _callcatch
      return scmutil.callcatch(ui, func)
    File "mercurial\scmutil.py", line 252, in callcatch
      ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
    File "mercurial\encoding.py", line 205, in unitolocal
      return tolocal(u.encode('utf-8'))
  AttributeError: 'bytes' object has no attribute 'encode'
Yuya Nishihara - Sept. 23, 2018, 6:45 a.m.
On Sat, 22 Sep 2018 11:28:44 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1537580667 14400
> #      Fri Sep 21 21:44:27 2018 -0400
> # Node ID ca417c9464d378661e9e962be1447647006297f3
> # Parent  f6dbc0131f506de7f3484946b2e1d90c2a087d74
> py3: create built in exceptions with str type messages in win32.py

Queued this, thanks.

Patch

diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -307,8 +307,8 @@  def _raiseoserror(name):
     if code > 0x7fffffff:
         code -= 2**32
     err = ctypes.WinError(code=code)
-    raise OSError(err.errno, '%s: %s' % (name,
-                                         encoding.strtolocal(err.strerror)))
+    raise OSError(err.errno, r'%s: %s' % (encoding.strfromlocal(name),
+                                          err.strerror))
 
 def _getfileinfo(name):
     fh = _kernel32.CreateFileA(name, 0,
@@ -597,7 +597,8 @@  def unlink(f):
         # use EPERM because it is POSIX prescribed value, even though
         # unlink(2) on directories returns EISDIR on Linux
         raise IOError(errno.EPERM,
-                      "Unlinking directory not permitted: '%s'" % f)
+                      r"Unlinking directory not permitted: '%s'"
+                      % encoding.strfromlocal(f))
 
     # POSIX allows to unlink and rename open files. Windows has serious
     # problems with doing that:
@@ -625,7 +626,7 @@  def unlink(f):
             if e.errno != errno.EEXIST:
                 raise
     else:
-        raise IOError(errno.EEXIST, "No usable temporary filename found")
+        raise IOError(errno.EEXIST, r"No usable temporary filename found")
 
     try:
         os.unlink(temp)