rados: use FormatErrorCode for formatting rados errors

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-08-10 11:04:32 -04:00 committed by John Mulligan
parent 33e84bc9c5
commit b6dff699e4
2 changed files with 2 additions and 7 deletions

View File

@ -7,7 +7,6 @@ import "C"
import ( import (
"errors" "errors"
"fmt"
"github.com/ceph/go-ceph/internal/errutil" "github.com/ceph/go-ceph/internal/errutil"
) )
@ -17,11 +16,7 @@ type radosError int
// Error returns the error string for the radosError type. // Error returns the error string for the radosError type.
func (e radosError) Error() string { func (e radosError) Error() string {
errno, s := errutil.FormatErrno(int(e)) return errutil.FormatErrorCode("rados", int(e))
if s == "" {
return fmt.Sprintf("rados: ret=%d", errno)
}
return fmt.Sprintf("rados: ret=%d, %s", errno, s)
} }
func (e radosError) ErrorCode() int { func (e radosError) ErrorCode() int {

View File

@ -13,7 +13,7 @@ func TestRadosError(t *testing.T) {
err = getError(-5) // IO error err = getError(-5) // IO error
assert.Error(t, err) assert.Error(t, err)
assert.Equal(t, err.Error(), "rados: ret=5, Input/output error") assert.Equal(t, err.Error(), "rados: ret=-5, Input/output error")
errno, ok := err.(interface{ ErrorCode() int }) errno, ok := err.(interface{ ErrorCode() int })
assert.True(t, ok) assert.True(t, ok)