mirror of https://github.com/ceph/go-ceph
rados: make RadosError type unexported
In order to avoid external dependencies on implementation details, this change replaces RadosError with the unexported radosError. In case some application really needs access to the integer value, it can use the pattern var errno interface{ Errno() int } if errors.As(err, errno) { ... errno.Errno() ... } Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
parent
6c944e8b65
commit
e77ecf68f6
|
@ -273,7 +273,7 @@ func (c *Conn) GetPoolByName(name string) (int64, error) {
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
ret := int64(C.rados_pool_lookup(c.cluster, c_name))
|
ret := int64(C.rados_pool_lookup(c.cluster, c_name))
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return 0, RadosError(ret)
|
return 0, radosError(ret)
|
||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ func (c *Conn) GetPoolByID(id int64) (string, error) {
|
||||||
c_id := C.int64_t(id)
|
c_id := C.int64_t(id)
|
||||||
ret := int(C.rados_pool_reverse_lookup(c.cluster, c_id, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
|
ret := int(C.rados_pool_reverse_lookup(c.cluster, c_id, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return "", RadosError(ret)
|
return "", radosError(ret)
|
||||||
}
|
}
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(&buf[0]))), nil
|
return C.GoString((*C.char)(unsafe.Pointer(&buf[0]))), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,11 @@ import (
|
||||||
"github.com/ceph/go-ceph/internal/errutil"
|
"github.com/ceph/go-ceph/internal/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// revive:disable:exported Temporarily live with stuttering
|
// radosError represents an error condition returned from the Ceph RADOS APIs.
|
||||||
|
type radosError int
|
||||||
|
|
||||||
// RadosError represents an error condition returned from the Ceph RADOS APIs.
|
// Error returns the error string for the radosError type.
|
||||||
type RadosError int
|
func (e radosError) Error() string {
|
||||||
|
|
||||||
// revive:enable:exported
|
|
||||||
|
|
||||||
// Error returns the error string for the RadosError type.
|
|
||||||
func (e RadosError) Error() string {
|
|
||||||
errno, s := errutil.FormatErrno(int(e))
|
errno, s := errutil.FormatErrno(int(e))
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return fmt.Sprintf("rados: ret=%d", errno)
|
return fmt.Sprintf("rados: ret=%d", errno)
|
||||||
|
@ -28,11 +24,15 @@ func (e RadosError) Error() string {
|
||||||
return fmt.Sprintf("rados: ret=%d, %s", errno, s)
|
return fmt.Sprintf("rados: ret=%d, %s", errno, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e radosError) Errno() int {
|
||||||
|
return int(e)
|
||||||
|
}
|
||||||
|
|
||||||
func getError(e C.int) error {
|
func getError(e C.int) error {
|
||||||
if e == 0 {
|
if e == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return RadosError(e)
|
return radosError(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getErrorIfNegative converts a ceph return code to error if negative.
|
// getErrorIfNegative converts a ceph return code to error if negative.
|
||||||
|
@ -52,15 +52,15 @@ var (
|
||||||
ErrNotConnected = errors.New("RADOS not connected")
|
ErrNotConnected = errors.New("RADOS not connected")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Public RadosErrors:
|
// Public radosErrors:
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ErrNotFound indicates a missing resource.
|
// ErrNotFound indicates a missing resource.
|
||||||
ErrNotFound = RadosError(-C.ENOENT)
|
ErrNotFound = radosError(-C.ENOENT)
|
||||||
// ErrPermissionDenied indicates a permissions issue.
|
// ErrPermissionDenied indicates a permissions issue.
|
||||||
ErrPermissionDenied = RadosError(-C.EPERM)
|
ErrPermissionDenied = radosError(-C.EPERM)
|
||||||
// ErrObjectExists indicates that an exclusive object creation failed.
|
// ErrObjectExists indicates that an exclusive object creation failed.
|
||||||
ErrObjectExists = RadosError(-C.EEXIST)
|
ErrObjectExists = radosError(-C.EEXIST)
|
||||||
|
|
||||||
// RadosErrorNotFound indicates a missing resource.
|
// RadosErrorNotFound indicates a missing resource.
|
||||||
//
|
//
|
||||||
|
@ -75,7 +75,7 @@ const (
|
||||||
// Private errors:
|
// Private errors:
|
||||||
|
|
||||||
const (
|
const (
|
||||||
errNameTooLong = RadosError(-C.ENAMETOOLONG)
|
errNameTooLong = radosError(-C.ENAMETOOLONG)
|
||||||
|
|
||||||
errRange = RadosError(-C.ERANGE)
|
errRange = radosError(-C.ERANGE)
|
||||||
)
|
)
|
||||||
|
|
|
@ -589,7 +589,7 @@ func (ioctx *IOContext) ListLockers(oid, name string) (*LockInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, RadosError(ret)
|
return nil, radosError(ret)
|
||||||
}
|
}
|
||||||
return &LockInfo{int(ret), c_exclusive == 1, C.GoString(c_tag), splitCString(c_clients, c_clients_len), splitCString(c_cookies, c_cookies_len), splitCString(c_addrs, c_addrs_len)}, nil
|
return &LockInfo{int(ret), c_exclusive == 1, C.GoString(c_tag), splitCString(c_clients, c_clients_len), splitCString(c_cookies, c_cookies_len), splitCString(c_addrs, c_addrs_len)}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue