From b22a7bb80f040a340976f8735eb40bd09c6bb9fd Mon Sep 17 00:00:00 2001 From: Changcheng Liu Date: Fri, 10 May 2019 13:47:30 +0800 Subject: [PATCH] python/rados: Add verbose rados exceptions message 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 Signed-off-by: Changcheng Liu --- src/pybind/rados/rados.pyx | 79 ++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 24da79c86cd14..de46161cd73eb 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -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, } -- 2.39.5