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 (
"errors"
"fmt"
"github.com/ceph/go-ceph/internal/errutil"
)
@ -17,11 +16,7 @@ type radosError int
// 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)
}
return fmt.Sprintf("rados: ret=%d, %s", errno, s)
return errutil.FormatErrorCode("rados", int(e))
}
func (e radosError) ErrorCode() int {

View File

@ -13,7 +13,7 @@ func TestRadosError(t *testing.T) {
err = getError(-5) // IO error
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 })
assert.True(t, ok)