From: Varsha Rao Date: Fri, 14 Jun 2019 11:18:08 +0000 (+0530) Subject: pybind: Print standard error messages X-Git-Tag: v14.2.5~213^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7791f5d211ce5d20a9700837ece6d2fc70c9a27f;p=ceph.git pybind: Print standard error messages 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 (cherry picked from commit 309b3f1e97db1af4639ab59d15fb9e33daee3bb0) --- diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 8e7b43b25e1..4b6ff29c766 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -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',