rbd: simplify error handling

This change replaces the sentinel errors in rbd module with
standard errors created with errors.New().

Related: #1203

Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
Sven Anderson
2020-07-10 03:05:42 +02:00
committed by mergify[bot]
parent dba2c27bcb
commit 92884f56f4
7 changed files with 61 additions and 167 deletions

View File

@ -151,12 +151,10 @@ func checkSnapCloneExists(ctx context.Context, parentVol *rbdVolume, rbdSnap *rb
// Fetch on-disk image attributes
err = vol.getImageInfo()
if err != nil {
var einf ErrImageNotFound
if errors.As(err, &einf) {
if errors.Is(err, ErrImageNotFound) {
err = parentVol.deleteSnapshot(ctx, rbdSnap)
if err != nil {
var esnf ErrSnapNotFound
if !errors.As(err, &esnf) {
if !errors.Is(err, ErrSnapNotFound) {
klog.Errorf(util.Log(ctx, "failed to delete snapshot %s: %v"), rbdSnap, err)
return false, err
}
@ -182,8 +180,7 @@ func checkSnapCloneExists(ctx context.Context, parentVol *rbdVolume, rbdSnap *rb
// check snapshot exists if not create it
err = vol.checkSnapExists(rbdSnap)
var esnf ErrSnapNotFound
if errors.As(err, &esnf) {
if errors.Is(err, ErrSnapNotFound) {
// create snapshot
sErr := vol.createSnapshot(ctx, rbdSnap)
if sErr != nil {
@ -281,8 +278,7 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er
// Fetch on-disk image attributes and compare against request
err = rv.getImageInfo()
if err != nil {
var einf ErrImageNotFound
if errors.As(err, &einf) {
if errors.Is(err, ErrImageNotFound) {
// Need to check cloned info here not on createvolume,
if parentVol != nil {
found, cErr := rv.checkCloneImage(ctx, parentVol)
@ -319,9 +315,8 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er
// size checks
if rv.VolSize < requestSize {
err = fmt.Errorf("image with the same name (%s) but with different size already exists",
rv.RbdImageName)
return false, ErrVolNameConflict{rv.RbdImageName, err}
return false, fmt.Errorf("%w: image with the same name (%s) but with different size already exists",
ErrVolNameConflict, rv.RbdImageName)
}
// TODO: We should also ensure image features and format is the same