From a47cfbc6c88498969356099f4934d45af1ea1672 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 25 Jun 2020 10:42:55 +0200 Subject: [PATCH] cleanup: use errors.As() in rbdVolume.Exists() and rbd.checkSnapExists() See-also: https://github.com/golang/go/wiki/ErrorValueFAQ#how-should-i-change-my-error-handling-code-to-work-with-the-new-features Signed-off-by: Niels de Vos --- internal/rbd/rbd_journal.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/rbd/rbd_journal.go b/internal/rbd/rbd_journal.go index 43521d82c..f2d1368e0 100644 --- a/internal/rbd/rbd_journal.go +++ b/internal/rbd/rbd_journal.go @@ -150,7 +150,8 @@ func checkSnapCloneExists(ctx context.Context, parentVol *rbdVolume, rbdSnap *rb // Fetch on-disk image attributes err = vol.getImageInfo() if err != nil { - if _, ok := err.(ErrImageNotFound); ok { + var esnf ErrSnapNotFound + if errors.As(err, &esnf) { err = parentVol.deleteSnapshot(ctx, rbdSnap) if err != nil { if _, ok := err.(ErrSnapNotFound); !ok { @@ -272,7 +273,8 @@ func (rv *rbdVolume) Exists(ctx context.Context) (bool, error) { // Fetch on-disk image attributes and compare against request err = rv.getImageInfo() if err != nil { - if _, ok := err.(ErrImageNotFound); ok { + var einf ErrImageNotFound + if errors.As(err, &einf) { err = j.UndoReservation(ctx, rv.JournalPool, rv.Pool, rv.RbdImageName, rv.RequestName) return false, err