]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: Print standard error messages
authorVarsha Rao <varao@redhat.com>
Fri, 14 Jun 2019 11:18:08 +0000 (16:48 +0530)
committerVarsha Rao <varao@redhat.com>
Tue, 18 Jun 2019 11:49:40 +0000 (17:19 +0530)
This patch modifies the error message to include standard error message.
Also adds ENOTEMPTY error code.

Fixes: https://tracker.ceph.com/issues/40411
Signed-off-by: Varsha Rao <varao@redhat.com>
src/pybind/cephfs/cephfs.pyx

index 98932fb9e9d56029d54e5e9966251fb660056280..2d8e422096f3990ab0004103963b7cf7b2db6007 100644 (file)
@@ -163,7 +163,7 @@ class OSError(Error):
         self.strerror = strerror
 
     def __str__(self):
-        return '[Errno {0}] {1}'.format(self.errno, self.strerror)
+        return '{0}: {1} [Errno {2}]'.format(self.strerror, os.strerror(self.errno), self.errno)
 
 
 class PermissionError(OSError):
@@ -210,6 +210,10 @@ class OutOfRange(OSError):
     pass
 
 
+class ObjectNotEmpty(OSError):
+    pass
+
+
 IF UNAME_SYSNAME == "FreeBSD":
     cdef errno_to_exception =  {
         errno.EPERM      : PermissionError,
@@ -222,6 +226,7 @@ IF UNAME_SYSNAME == "FreeBSD":
         errno.EOPNOTSUPP : OperationNotSupported,
         errno.ERANGE     : OutOfRange,
         errno.EWOULDBLOCK: WouldBlock,
+        errno.ENOTEMPTY  : ObjectNotEmpty,
     }
 ELSE:
     cdef errno_to_exception =  {
@@ -235,6 +240,7 @@ ELSE:
         errno.EOPNOTSUPP : OperationNotSupported,
         errno.ERANGE     : OutOfRange,
         errno.EWOULDBLOCK: WouldBlock,
+        errno.ENOTEMPTY  : ObjectNotEmpty,
     }
 
 
@@ -252,7 +258,7 @@ cdef make_ex(ret, msg):
     if ret in errno_to_exception:
         return errno_to_exception[ret](ret, msg)
     else:
-        return Error(ret, msg + (": error code %d" % ret))
+        return Error(msg + ': {} [Errno {:d}]'.format(os.strerror(ret), ret))
 
 
 class DirEntry(namedtuple('DirEntry',