cephfs: make CephFSError type unexported

In order to avoid external dependencies on implementation details,
this change replaces CephFSError with the unexported cephFSError. 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:58:54 +02:00 committed by John Mulligan
parent e77ecf68f6
commit 8b45a01b7d

View File

@ -11,15 +11,11 @@ import (
"github.com/ceph/go-ceph/internal/errutil"
)
// revive:disable:exported Temporarily live with stuttering
// cephFSError represents an error condition returned from the CephFS APIs.
type cephFSError int
// CephFSError represents an error condition returned from the CephFS APIs.
type CephFSError int
// revive:enable:exported
// Error returns the error string for the CephFSError type.
func (e CephFSError) Error() string {
// Error returns the error string for the cephFSError type.
func (e cephFSError) Error() string {
errno, s := errutil.FormatErrno(int(e))
if s == "" {
return fmt.Sprintf("cephfs: ret=%d", errno)
@ -27,11 +23,15 @@ func (e CephFSError) Error() string {
return fmt.Sprintf("cephfs: ret=%d, %s", errno, s)
}
func (e cephFSError) Errno() int {
return int(e)
}
func getError(e C.int) error {
if e == 0 {
return nil
}
return CephFSError(e)
return cephFSError(e)
}
// Public go errors:
@ -39,13 +39,13 @@ func getError(e C.int) error {
const (
// ErrNotConnected may be returned when client is not connected
// to a cluster.
ErrNotConnected = CephFSError(-C.ENOTCONN)
ErrNotConnected = cephFSError(-C.ENOTCONN)
)
// Private errors:
const (
errInvalid = CephFSError(-C.EINVAL)
errNameTooLong = CephFSError(-C.ENAMETOOLONG)
errNoEntry = CephFSError(-C.ENOENT)
errInvalid = cephFSError(-C.EINVAL)
errNameTooLong = cephFSError(-C.ENAMETOOLONG)
errNoEntry = cephFSError(-C.ENOENT)
)