rbd: use FormatErrorCode for formatting rbd errors

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-08-10 11:04:52 -04:00 committed by John Mulligan
parent b6dff699e4
commit 849fc3c1f3
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"
)
@ -16,11 +15,7 @@ import (
type rbdError int
func (e rbdError) Error() string {
errno, s := errutil.FormatErrno(int(e))
if s == "" {
return fmt.Sprintf("rbd: ret=%d", errno)
}
return fmt.Sprintf("rbd: ret=%d, %s", errno, s)
return errutil.FormatErrorCode("rbd", int(e))
}
func (e rbdError) ErrorCode() int {

View File

@ -13,7 +13,7 @@ func TestRBDError(t *testing.T) {
err = getError(-39) // NOTEMPTY (image still has a snapshot)
assert.Error(t, err)
assert.Equal(t, err.Error(), "rbd: ret=39, Directory not empty")
assert.Equal(t, err.Error(), "rbd: ret=-39, Directory not empty")
errno, ok := err.(interface{ ErrorCode() int })
assert.True(t, ok)