mirror of
https://github.com/ceph/go-ceph
synced 2024-12-22 22:24:03 +00:00
8b45a01b7d
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>
52 lines
930 B
Go
52 lines
930 B
Go
package cephfs
|
|
|
|
/*
|
|
#include <errno.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ceph/go-ceph/internal/errutil"
|
|
)
|
|
|
|
// cephFSError represents an error condition returned from the CephFS APIs.
|
|
type cephFSError int
|
|
|
|
// 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)
|
|
}
|
|
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)
|
|
}
|
|
|
|
// Public go errors:
|
|
|
|
const (
|
|
// ErrNotConnected may be returned when client is not connected
|
|
// to a cluster.
|
|
ErrNotConnected = cephFSError(-C.ENOTCONN)
|
|
)
|
|
|
|
// Private errors:
|
|
|
|
const (
|
|
errInvalid = cephFSError(-C.EINVAL)
|
|
errNameTooLong = cephFSError(-C.ENAMETOOLONG)
|
|
errNoEntry = cephFSError(-C.ENOENT)
|
|
)
|