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:
Sven Anderson 2020-07-14 01:51:20 +02:00 committed by John Mulligan
parent 6c944e8b65
commit e77ecf68f6
3 changed files with 18 additions and 18 deletions

View File

@ -273,7 +273,7 @@ func (c *Conn) GetPoolByName(name string) (int64, error) {
defer C.free(unsafe.Pointer(c_name))
ret := int64(C.rados_pool_lookup(c.cluster, c_name))
if ret < 0 {
return 0, RadosError(ret)
return 0, radosError(ret)
}
return ret, nil
}
@ -287,7 +287,7 @@ func (c *Conn) GetPoolByID(id int64) (string, error) {
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))))
if ret < 0 {
return "", RadosError(ret)
return "", radosError(ret)
}
return C.GoString((*C.char)(unsafe.Pointer(&buf[0]))), nil
}

View File

@ -12,15 +12,11 @@ import (
"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.
type RadosError int
// revive:enable:exported
// Error returns the error string for the RadosError type.
func (e RadosError) Error() string {
// Error returns the error string for the radosError type.
func (e radosError) Error() string {
errno, s := errutil.FormatErrno(int(e))
if s == "" {
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)
}
func (e radosError) Errno() int {
return int(e)
}
func getError(e C.int) error {
if e == 0 {
return nil
}
return RadosError(e)
return radosError(e)
}
// getErrorIfNegative converts a ceph return code to error if negative.
@ -52,15 +52,15 @@ var (
ErrNotConnected = errors.New("RADOS not connected")
)
// Public RadosErrors:
// Public radosErrors:
const (
// ErrNotFound indicates a missing resource.
ErrNotFound = RadosError(-C.ENOENT)
ErrNotFound = radosError(-C.ENOENT)
// ErrPermissionDenied indicates a permissions issue.
ErrPermissionDenied = RadosError(-C.EPERM)
ErrPermissionDenied = radosError(-C.EPERM)
// ErrObjectExists indicates that an exclusive object creation failed.
ErrObjectExists = RadosError(-C.EEXIST)
ErrObjectExists = radosError(-C.EEXIST)
// RadosErrorNotFound indicates a missing resource.
//
@ -75,7 +75,7 @@ const (
// Private errors:
const (
errNameTooLong = RadosError(-C.ENAMETOOLONG)
errNameTooLong = radosError(-C.ENAMETOOLONG)
errRange = RadosError(-C.ERANGE)
errRange = radosError(-C.ERANGE)
)

View File

@ -589,7 +589,7 @@ func (ioctx *IOContext) ListLockers(oid, name string) (*LockInfo, error) {
}
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
}