-
Notifications
You must be signed in to change notification settings - Fork 72
fix: Handle response error when nil #709
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #709 +/- ##
===========================================
- Coverage 69.81% 58.53% -11.28%
===========================================
Files 15 25 +10
Lines 2597 3806 +1209
===========================================
+ Hits 1813 2228 +415
- Misses 666 1436 +770
- Partials 118 142 +24 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2b7cb64
to
ea9fb7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates error handling in GetACISubnet
to guard against nil response errors and replaces deprecated runtime.WithCaptureResponse
calls with policy.WithCaptureResponse
across client methods.
- Added a nil check for
respErr.RawResponse
inGetACISubnet
to prevent nil pointer dereference. - Replaced all
runtime.WithCaptureResponse
usages with the newpolicy.WithCaptureResponse
API. - Updated imports to remove the deprecated
runtime
package and adjust grouping.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
pkg/network/aci_network.go | Guarded against nil respErr.RawResponse and switched to policy.WithCaptureResponse |
pkg/client/client_apis.go | Replaced runtime.WithCaptureResponse with policy.WithCaptureResponse and tweaked error checks |
Comments suppressed due to low confidence (1)
pkg/network/aci_network.go:217
- [nitpick] Consider adding a unit test for the case where
respErr.RawResponse
is nil inGetACISubnet
to verify that the function does not panic and returns the expected error.
respErr.RawResponse != nil &&
if errors.As(err, &rawResponse) && | ||
rawResponse.StatusCode == http.StatusNotFound { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using errors.As to match *http.Response will always fail since err is not a *http.Response. Replace this condition with: if rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound
.
if errors.As(err, &rawResponse) && | |
rawResponse.StatusCode == http.StatusNotFound { | |
if rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound { |
Copilot uses AI. Check for mistakes.
if errors.As(err, &rawResponse) && | ||
rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.As cannot extract *http.Response from err. Change this check to if rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound
to correctly detect NotFound responses.
if errors.As(err, &rawResponse) && | |
rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound { | |
if rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound { |
Copilot uses AI. Check for mistakes.
ea9fb7b
to
96f8828
Compare
Signed-off-by: Heba Elayoty <heelayot@microsoft.com>
…sCode Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Heba <31887807+helayoty@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Heba <31887807+helayoty@users.noreply.github.com>
96f8828
to
e9c4e2c
Compare
In
GetACISubnet
function, the response error is not handled byerrors.As(err, &respErr)
, which will cause nil pointer dereference when the response error is nil.runtime.WithCaptureResponse
is deprecated in favor ofpolicy.WithCaptureResponse