Skip to content

Replace verbose azcore errors with more concise ones#3783

Merged
thomas11 merged 1 commit into
masterfrom
tkappler/azcore-error
Dec 12, 2024
Merged

Replace verbose azcore errors with more concise ones#3783
thomas11 merged 1 commit into
masterfrom
tkappler/azcore-error

Conversation

@thomas11

@thomas11 thomas11 commented Dec 12, 2024

Copy link
Copy Markdown
Contributor

Fixes #3778

Before:

$ pulumi up --skip-preview
...
Diagnostics:
  pulumi:pulumi:Stack (azn-http-errors-dev):
    error: update failed

  azure-native:storage:StorageAccount (sa):
    error: PUT https://management.azure.com/subscriptions/123/resourceGroups/resourceGroup84362436/providers/Microsoft.Storage/storageAccounts/INVALID
    --------------------------------------------------------------------------------
    RESPONSE 400: 400 Bad Request
    ERROR CODE: AccountNameInvalid
    --------------------------------------------------------------------------------
    {
      "error": {
        "code": "AccountNameInvalid",
        "message": "INVALID is not a valid storage account name. Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only."
      }
    }
    --------------------------------------------------------------------------------

...

After:

$ PATH=$HOME/pulumi/pulumi-azure-native/bin:$PATH pulumi up --skip-preview
...
  azure-native:storage:StorageAccount (sa):
    error: Code="AccountNameInvalid" Message="INVALID is not a valid storage account name. Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only."

...

@thomas11 thomas11 self-assigned this Dec 12, 2024
@github-actions

Copy link
Copy Markdown
Contributor

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@codecov

codecov Bot commented Dec 12, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 79.31034% with 6 lines in your changes missing coverage. Please review.

Project coverage is 56.71%. Comparing base (08681c2) to head (6a3f84f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
provider/pkg/azure/client_azcore.go 79.31% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3783      +/-   ##
==========================================
+ Coverage   56.65%   56.71%   +0.05%     
==========================================
  Files          78       78              
  Lines       11975    11999      +24     
==========================================
+ Hits         6785     6805      +20     
- Misses       4689     4691       +2     
- Partials      501      503       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return nil, nil
}

func newResponseError(resp *http.Response) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to call it in shouldRetryConflict too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error in shouldRetryConflict is never shown to the user. We only access its ErrorCode.

Comment thread provider/pkg/azure/client_azcore.go
Comment thread provider/pkg/azure/client_azcore.go
@thomas11 thomas11 merged commit 4d9c25d into master Dec 12, 2024
@thomas11 thomas11 deleted the tkappler/azcore-error branch December 12, 2024 11:24
@pulumi-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped in release v2.78.0.

thomas11 added a commit that referenced this pull request Jan 10, 2025
Fixes an issue I discovered today when trying to reproduce another issue
report. `pulumi refresh` is broken for this provider:
```
$ PATH="$HOME/pulumi/pan/bin:$PATH" pulumi refresh --skip-preview -s dev

     pulumi:pulumi:Stack                      recoveryservices-protecteditem-dev  **failed**                1 error; 4 warnings
 ~   ├─ azure-native:resources:ResourceGroup  resourceGroup                       **refreshing failed**     1 error

  azure-native:resources:ResourceGroup (resourceGroup):
    error: Code="ResourceGroupNotFound" Message="Resource group 'resourceGroup3f871416' could not be found."
```

The reason is that #3783 regressed `azure.IsNotFound`, causing `Read` to
report an error when a resource doesn't exist in Azure.

This PR fixes the problem and adds test coverage.
@EronWright

Copy link
Copy Markdown
Contributor

A possible follow-up is to handle the final error message of long-running operations, as returned by the poller as an azcore.ResponseError.

EronWright added a commit that referenced this pull request Feb 25, 2025
This PR fixes an error that occurs in the deletion of a (non-existent)
Azure resource. The issue impacts resources that have an async-style
DELETE call (as is the case for Subnet, see
[schema](https://github.com/Azure/azure-rest-api-specs/blob/1b038fc40563bdafb343a71cd5f7d3dee6bc4b5b/specification/network/resource-manager/Microsoft.Network/stable/2019-02-01/virtualNetwork.json#L396-L399)).
The technical detail is that the 404 may come in the initial response as
opposed to during polling, and that wasn't handled correctly..

The user-facing error is:
```
  azure-native:network:Subnet (subnet):
    error: the operation failed or was cancelled
```

The call to `runtime.NewPoller` should not be made with a failed
response, otherwise we hit a precondition within it:
```go
	// this is a back-stop in case the swagger is incorrect (i.e. missing one or more status codes for success).
	// ideally the codegen should return an error if the initial response failed and not even create a poller.
	if !poller.StatusCodeValid(resp) {
		return nil, errors.New("the operation failed or was cancelled")
	}
```

To fix, I encapsulated the request-to-final-response logic into an
anonymous function, to be able to uniformly check for the 404 result.
And I ensure that the initial response was successful before making a
poller.

This PR relaxes the logic for detecting a 404 during resource deletion,
to not care about the specific error code. I find that at least two
codes are possible: `ResourceNotFound` and `ResourceGroupNotFound`. Note
that the sync path did not check the error code anyway and a uniform
solution is desirable.

TODO:

- [x] new unit tests
- [x] manual testing for various types of resources (w/ sync and async
delete operations).

Closes #3978
See also: #3783
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage Account creation error prints the entire HTTP response

5 participants