From 8e4cf26f716ed50abd9d3efc74d0297dfba633ae Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Wed, 4 Jan 2023 14:55:19 +0000 Subject: [PATCH] Handle both error and error pointer returns from gophercloud --- pkg/utils/errors/errors.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/utils/errors/errors.go b/pkg/utils/errors/errors.go index e61ce4817b..f5fcfa5924 100644 --- a/pkg/utils/errors/errors.go +++ b/pkg/utils/errors/errors.go @@ -33,13 +33,15 @@ func IsRetryable(err error) bool { } func IsNotFound(err error) bool { + // Gophercloud is not consistent in how it returns 404 errors. Sometimes + // it returns a pointer to the error, sometimes it returns the error + // directly. + // Some discussion here: https://github.com/gophercloud/gophercloud/issues/2279 var errDefault404 gophercloud.ErrDefault404 - if errors.As(err, &errDefault404) { - return true - } - - var errResourceNotFound gophercloud.ErrResourceNotFound - if errors.As(err, &errResourceNotFound) { + var pErrDefault404 *gophercloud.ErrDefault404 + var errNotFound gophercloud.ErrResourceNotFound + var pErrNotFound *gophercloud.ErrResourceNotFound + if errors.As(err, &errDefault404) || errors.As(err, &pErrDefault404) || errors.As(err, &errNotFound) || errors.As(err, &pErrNotFound) { return true }