Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(&azcore.ResponseError{RawResponse: &http.Response{}}).Error() panics #22147

Closed
jim-minter opened this issue Dec 14, 2023 · 3 comments · Fixed by #22148 or #22149
Closed

(&azcore.ResponseError{RawResponse: &http.Response{}}).Error() panics #22147

jim-minter opened this issue Dec 14, 2023 · 3 comments · Fixed by #22148 or #22149
Assignees

Comments

@jim-minter
Copy link
Member

Bug Report

  • import path of package in question: "github.com/Azure/azure-sdk-for-go/sdk/azcore"
  • SDK version: v1.9.0
  • output of go version: go version go1.21.4 linux/amd64

Similar issue to #21838.

The expression (&azcore.ResponseError{RawResponse: &http.Response{}}).Error() panics. This is because runtime.Payload(&http.Response{}) panics, because it calls the standard library function io.ReadAll on a nil resp.Body and io.ReadAll doesn't nil-check its Reader (golang/go#64714).

For completeness, note that runtime.Payload(nil) also panics because it doesn't nil-check resp, but I think that code path is not reachable via azcore.ResponseError. It'd be nice to fix for other callers of runtime.Payload() though.

This isn't something that we see is causing a production problem (although perhaps there is a minor robustness issue in the highly improbable production case that any of these fields is not set).

But, it's something that trips us up from time to time in a unit test context - when unit testing some other behavior, it's possible to inadvertently instantiate a ResponseError that will then cause a panic when Error() is called.

If only to simplify unit testing, it would be neat if (*azcore.ResponseError) Error() did not panic on &azcore.ResponseError{RawResponse: &http.Response{}}.

@github-actions github-actions bot added Azure.Core Client This issue points to a problem in the data-plane of the library. needs-team-triage Workflow: This issue needs the team to triage. labels Dec 14, 2023
@jhendrixMSFT jhendrixMSFT removed Client This issue points to a problem in the data-plane of the library. needs-team-triage Workflow: This issue needs the team to triage. labels Dec 14, 2023
@jhendrixMSFT jhendrixMSFT self-assigned this Dec 14, 2023
@jhendrixMSFT
Copy link
Member

We can fix this, but note that per the docs, the response body will never be nil (http.NoBody when there's no body).

@jhendrixMSFT
Copy link
Member

Fix will be in internal@v1.5.2 to be released in early Jan.

@jhendrixMSFT
Copy link
Member

Release will go out week of 2/5

@github-actions github-actions bot locked and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants