]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
python/rados: Add verbose rados exceptions message 28054/head
authorChangcheng Liu <changcheng.liu@aliyun.com>
Fri, 10 May 2019 05:47:30 +0000 (13:47 +0800)
committerChangcheng Liu <changcheng.liu@aliyun.com>
Tue, 9 Jul 2019 08:26:44 +0000 (16:26 +0800)
Add type of exception detail to rados exceptions to trace up to the
calling driver to show failure message info.

Signed-off-by: Daniel Badea <daniel.badea@windriver.com>
Signed-off-by: Changcheng Liu <changcheng.liu@aliyun.com>
src/pybind/rados/rados.pyx

index 24da79c86cd14db291861a7b98fbba476709a9cf..de46161cd73ebfb4cc88182353bc19a141c37e01 100644 (file)
@@ -351,7 +351,10 @@ class Error(Exception):
         return (self.__class__, (self.message, self.errno))
 
 class InvalidArgumentError(Error):
-    pass
+    def __init__(self, message, errno=None):
+        super(InvalidArgumentError, self).__init__(
+            "RADOS invalid argument (%s)" % message, errno)
+
 
 class OSError(Error):
     """ `OSError` class, derived from `Error` """
@@ -359,72 +362,114 @@ class OSError(Error):
 
 class InterruptedOrTimeoutError(OSError):
     """ `InterruptedOrTimeoutError` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(InterruptedOrTimeoutError, self).__init__(
+            "RADOS interrupted or timeout (%s)" % message, errno)
 
 
 class PermissionError(OSError):
     """ `PermissionError` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(PermissionError, self).__init__(
+            "RADOS permission error (%s)" % message, errno)
 
 
 class PermissionDeniedError(OSError):
     """ deal with EACCES related. """
-    pass
+    def __init__(self, message, errno=None):
+        super(PermissionDeniedError, self).__init__(
+                "RADOS permission denied (%s)" % message, errno)
 
 
 class ObjectNotFound(OSError):
     """ `ObjectNotFound` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(ObjectNotFound, self).__init__(
+                "RADOS object not found (%s)" % message, errno)
 
 
 class NoData(OSError):
     """ `NoData` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(NoData, self).__init__(
+                "RADOS no data (%s)" % message, errno)
 
 
 class ObjectExists(OSError):
     """ `ObjectExists` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(ObjectExists, self).__init__(
+                "RADOS object exists (%s)" % message, errno)
 
 
 class ObjectBusy(OSError):
     """ `ObjectBusy` class, derived from `IOError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(ObjectBusy, self).__init__(
+                "RADOS object busy (%s)" % message, errno)
 
 
 class IOError(OSError):
     """ `ObjectBusy` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(IOError, self).__init__(
+                "RADOS I/O error (%s)" % message, errno)
 
 
 class NoSpace(OSError):
     """ `NoSpace` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(NoSpace, self).__init__(
+                "RADOS no space (%s)" % message, errno)
 
 
 class RadosStateError(Error):
     """ `RadosStateError` class, derived from `Error` """
-    pass
+    def __init__(self, message, errno=None):
+        super(RadosStateError, self).__init__(
+                "RADOS rados state (%s)" % message, errno)
 
 
 class IoctxStateError(Error):
     """ `IoctxStateError` class, derived from `Error` """
-    pass
+    def __init__(self, message, errno=None):
+        super(IoctxStateError, self).__init__(
+                "RADOS Ioctx state error (%s)" % message, errno)
 
 
 class ObjectStateError(Error):
     """ `ObjectStateError` class, derived from `Error` """
-    pass
+    def __init__(self, message, errno=None):
+        super(ObjectStateError, self).__init__(
+                "RADOS object state error (%s)" % message, errno)
 
 
 class LogicError(Error):
     """ `` class, derived from `Error` """
-    pass
+    def __init__(self, message, errno=None):
+        super(LogicError, self).__init__(
+            "RADOS logic error (%s)" % message, errno)
 
 
 class TimedOut(OSError):
     """ `TimedOut` class, derived from `OSError` """
-    pass
+    def __init__(self, message, errno=None):
+        super(TimedOut, self).__init__(
+                "RADOS timed out (%s)" % message, errno)
+
+
+class InProgress(Error):
+    """ `InProgress` class, derived from `Error` """
+    def __init__(self, message, errno=None):
+        super(InProgress, self).__init__(
+                "RADOS in progress error (%s)" % message, errno)
+
+
+class IsConnected(Error):
+    """ `IsConnected` class, derived from `Error` """
+    def __init__(self, message, errno=None):
+        super(IsConnected, self).__init__(
+                "RADOS is connected error (%s)" % message, errno)
 
 
 IF UNAME_SYSNAME == "FreeBSD":
@@ -439,6 +484,8 @@ IF UNAME_SYSNAME == "FreeBSD":
         errno.EINTR     : InterruptedOrTimeoutError,
         errno.ETIMEDOUT : TimedOut,
         errno.EACCES    : PermissionDeniedError,
+        errno.EINPROGRESS : InProgress,
+        errno.EISCONN   : IsConnected,
         errno.EINVAL    : InvalidArgumentError,
     }
 ELSE:
@@ -453,6 +500,8 @@ ELSE:
         errno.EINTR     : InterruptedOrTimeoutError,
         errno.ETIMEDOUT : TimedOut,
         errno.EACCES    : PermissionDeniedError,
+        errno.EINPROGRESS : InProgress,
+        errno.EISCONN   : IsConnected,
         errno.EINVAL    : InvalidArgumentError,
     }