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

Matt Harbison mharbison72 at gmail.com
Sat Sep 22 11:28:44 EDT 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at 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'

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)


More information about the Mercurial-devel mailing list