mirror of
https://github.com/ceph/go-ceph
synced 2025-02-16 18:47:23 +00:00
rados: Change RadoError Error() interface to provide meaningful string, even for non-default cases GetRadosError().
I got a "rados: ret=-22" message as part of call I made. I'm a bit rusty with my C stderror codes, which made the error a bit unhelpful. This commit makes this particular error come out as "rados: invalid argument", even if we don't need to explicitly create a Rados error variable for invalid argument case. It does so by using C.strerror(). A further change is that with this, we do not need to explicitly code RadosErrorNotFound and RadosErrorPermissionsDenied using a different error type thank RadosError.
This commit is contained in:
parent
f74dc6c3c6
commit
3d88c03e6e
@ -7,7 +7,6 @@ package rados
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
@ -15,20 +14,17 @@ import (
|
||||
type RadosError int
|
||||
|
||||
func (e RadosError) Error() string {
|
||||
return fmt.Sprintf("rados: ret=%d", e)
|
||||
return fmt.Sprintf("rados: %s", C.GoString(C.strerror(C.int(-e))))
|
||||
}
|
||||
|
||||
var RadosErrorNotFound = errors.New("Rados error not found")
|
||||
var RadosErrorNotFound = RadosError(-C.ENOENT)
|
||||
var RadosErrorPermissionDenied = RadosError(-C.EPERM)
|
||||
|
||||
func GetRadosError(err int) error {
|
||||
if err != 0 {
|
||||
if err == -C.ENOENT {
|
||||
return RadosErrorNotFound
|
||||
}
|
||||
return RadosError(err)
|
||||
} else {
|
||||
if err == 0 {
|
||||
return nil
|
||||
}
|
||||
return RadosError(err)
|
||||
}
|
||||
|
||||
// Version returns the major, minor, and patch components of the version of
|
||||
|
Loading…
Reference in New Issue
Block a user