From 0eba90ce860366378796e07697177c20ff97c0e9 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Fri, 11 Feb 2022 15:16:23 +1100 Subject: [PATCH] clean up error wrapping handling --- ...rce_cloudflare_custom_hostname_fallback_origin.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cloudflare/resource_cloudflare_custom_hostname_fallback_origin.go b/cloudflare/resource_cloudflare_custom_hostname_fallback_origin.go index f0213310395..b5bd72e4940 100644 --- a/cloudflare/resource_cloudflare_custom_hostname_fallback_origin.go +++ b/cloudflare/resource_cloudflare_custom_hostname_fallback_origin.go @@ -31,7 +31,7 @@ func resourceCloudflareCustomHostnameFallbackOriginRead(d *schema.ResourceData, customHostnameFallbackOrigin, err := client.CustomHostnameFallbackOrigin(context.Background(), zoneID) if err != nil { - return errors.Wrap(err, fmt.Sprintf("error reading custom hostname fallback origin %q", zoneID)) + return fmt.Errorf("error reading custom hostname fallback origin %q: %w", zoneID, err)) } d.Set("origin", customHostnameFallbackOrigin.Origin) @@ -46,7 +46,7 @@ func resourceCloudflareCustomHostnameFallbackOriginDelete(d *schema.ResourceData err := client.DeleteCustomHostnameFallbackOrigin(context.Background(), zoneID) if err != nil { - return errors.Wrap(err, "failed to delete custom hostname fallback origin") + return fmt.Errorf("failed to delete custom hostname fallback origin: %w", err) } return nil @@ -64,17 +64,18 @@ func resourceCloudflareCustomHostnameFallbackOriginCreate(d *schema.ResourceData return resource.Retry(d.Timeout(schema.TimeoutDefault), func() *resource.RetryError { _, err := client.UpdateCustomHostnameFallbackOrigin(context.Background(), zoneID, fallbackOrigin) if err != nil { + //nolint:errorlint if errors.As(err, &cloudflare.APIRequestError{}) && err.(*cloudflare.APIRequestError).InternalErrorCodeIs(1414) { return resource.RetryableError(fmt.Errorf("expected custom hostname resource to be ready for modification but is still pending")) } else { - return resource.NonRetryableError(errors.Wrap(err, "failed to create custom hostname fallback origin")) + return resource.NonRetryableError(fmt.Errorf("failed to create custom hostname fallback origin: %w", err)) } } fallbackHostname, err := client.CustomHostnameFallbackOrigin(context.Background(), zoneID) if err != nil { - return resource.NonRetryableError(fmt.Errorf("failed to fetch custom hostname: %s", err)) + return resource.NonRetryableError(fmt.Errorf("failed to fetch custom hostname: %w", err)) } // Address an eventual consistency issue where deleting a fallback hostname @@ -105,10 +106,11 @@ func resourceCloudflareCustomHostnameFallbackOriginUpdate(d *schema.ResourceData return resource.Retry(d.Timeout(schema.TimeoutDefault), func() *resource.RetryError { _, err := client.UpdateCustomHostnameFallbackOrigin(context.Background(), zoneID, fallbackOrigin) if err != nil { + //nolint:errorlint if errors.As(err, &cloudflare.APIRequestError{}) && err.(*cloudflare.APIRequestError).InternalErrorCodeIs(1414) { return resource.RetryableError(fmt.Errorf("expected custom hostname resource to be ready for modification but is still pending")) } - return resource.NonRetryableError(errors.Wrap(err, "failed to update custom hostname fallback origin")) + return resource.NonRetryableError(fmt.Errorf("failed to update custom hostname fallback origin: %w", err)) } resourceCloudflareCustomHostnameFallbackOriginRead(d, meta)