Skip to content

Commit

Permalink
Improve error handling in account read and delete functions
Browse files Browse the repository at this point in the history
This commit eliminates a redundant variable declaration from the
resourceCloudflareAccountRead function and surfaces some additional
information (the account ID) on account deletion failure cases.

Closes #2437

```release-note:enhancement
resource/cloudflare_account: Improve error handling of resourceCloudflareAccountDelete
```
  • Loading branch information
therealdwright committed May 17, 2023
1 parent 483e9b5 commit 9f6fe19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/2436.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_account: Improve error handling of resourceCloudflareAccountDelete
```
5 changes: 2 additions & 3 deletions internal/sdkv2provider/resource_cloudflare_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func resourceCloudflareAccountRead(ctx context.Context, d *schema.ResourceData,

foundAcc, _, err := client.Account(ctx, accountID)
if err != nil {
var notFoundError *cloudflare.NotFoundError
if errors.As(err, &notFoundError) {
if errors.As(err, &cloudflare.NotFoundError{}) {
tflog.Info(ctx, fmt.Sprintf("Account %s no longer exists", d.Id()))
d.SetId("")
return nil
Expand Down Expand Up @@ -118,7 +117,7 @@ func resourceCloudflareAccountDelete(ctx context.Context, d *schema.ResourceData
err := client.DeleteAccount(ctx, accountID)

if err != nil {
return diag.FromErr(fmt.Errorf("error deleting Cloudflare Account: %w", err))
return diag.FromErr(fmt.Errorf("error deleting Cloudflare Account %q: %w", accountID, err))
}

return nil
Expand Down

0 comments on commit 9f6fe19

Please sign in to comment.