]> 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)
committerNathan Cutler <ncutler@suse.com>
Fri, 30 Aug 2019 08:08:46 +0000 (10:08 +0200)
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>
(cherry picked from commit 309b3f1e97db1af4639ab59d15fb9e33daee3bb0)

src/pybind/cephfs/cephfs.pyx

index 8e7b43b25e12ce54ad7eaca27c07c4f2fa8c100d..4b6ff29c766b1248472fcc05a423e5484332080b 100644 (file)
@@ -164,7 +164,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):
@@ -211,6 +211,10 @@ class OutOfRange(OSError):
     pass
 
 
+class ObjectNotEmpty(OSError):
+    pass
+
+
 IF UNAME_SYSNAME == "FreeBSD":
     cdef errno_to_exception =  {
         errno.EPERM      : PermissionError,
@@ -223,6 +227,7 @@ IF UNAME_SYSNAME == "FreeBSD":
         errno.EOPNOTSUPP : OperationNotSupported,
         errno.ERANGE     : OutOfRange,
         errno.EWOULDBLOCK: WouldBlock,
+        errno.ENOTEMPTY  : ObjectNotEmpty,
     }
 ELSE:
     cdef errno_to_exception =  {
@@ -236,6 +241,7 @@ ELSE:
         errno.EOPNOTSUPP : OperationNotSupported,
         errno.ERANGE     : OutOfRange,
         errno.EWOULDBLOCK: WouldBlock,
+        errno.ENOTEMPTY  : ObjectNotEmpty,
     }
 
 
@@ -253,7 +259,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',