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 <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-25 10:42:55 +02:00 committed by mergify[bot]
parent d4dad7c189
commit a47cfbc6c8

View File

@ -150,7 +150,8 @@ func checkSnapCloneExists(ctx context.Context, parentVol *rbdVolume, rbdSnap *rb
// Fetch on-disk image attributes // Fetch on-disk image attributes
err = vol.getImageInfo() err = vol.getImageInfo()
if err != nil { if err != nil {
if _, ok := err.(ErrImageNotFound); ok { var esnf ErrSnapNotFound
if errors.As(err, &esnf) {
err = parentVol.deleteSnapshot(ctx, rbdSnap) err = parentVol.deleteSnapshot(ctx, rbdSnap)
if err != nil { if err != nil {
if _, ok := err.(ErrSnapNotFound); !ok { 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 // Fetch on-disk image attributes and compare against request
err = rv.getImageInfo() err = rv.getImageInfo()
if err != nil { if err != nil {
if _, ok := err.(ErrImageNotFound); ok { var einf ErrImageNotFound
if errors.As(err, &einf) {
err = j.UndoReservation(ctx, rv.JournalPool, rv.Pool, err = j.UndoReservation(ctx, rv.JournalPool, rv.Pool,
rv.RbdImageName, rv.RequestName) rv.RbdImageName, rv.RequestName)
return false, err return false, err