这是indexloc提供的服务,不要输入任何密码
Skip to content

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

Closed

Conversation

helayoty
Copy link
Member

  • In GetACISubnet function, the response error is not handled by errors.As(err, &respErr), which will cause nil pointer dereference when the response error is nil.

  • runtime.WithCaptureResponse is deprecated in favor of policy.WithCaptureResponse

Copilot

This comment was marked as outdated.

Copy link

codecov bot commented Jun 17, 2025

Codecov Report

Attention: Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.

Project coverage is 58.53%. Comparing base (b3460ff) to head (e9c4e2c).
Report is 72 commits behind head on master.

Files with missing lines Patch % Lines
pkg/client/client_apis.go 0.00% 17 Missing ⚠️
pkg/network/aci_network.go 0.00% 6 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

@helayoty helayoty requested a review from Copilot June 17, 2025 22:53
Copy link

@Copilot Copilot AI left a 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 in GetACISubnet to prevent nil pointer dereference.
  • Replaced all runtime.WithCaptureResponse usages with the new policy.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 in GetACISubnet to verify that the function does not panic and returns the expected error.
			respErr.RawResponse != nil &&

Comment on lines +111 to +112
if errors.As(err, &rawResponse) &&
rawResponse.StatusCode == http.StatusNotFound {
Copy link
Preview

Copilot AI Jun 17, 2025

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.

Suggested change
if errors.As(err, &rawResponse) &&
rawResponse.StatusCode == http.StatusNotFound {
if rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound {

Copilot uses AI. Check for mistakes.

Comment on lines +164 to +165
if errors.As(err, &rawResponse) &&
rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound {
Copy link
Preview

Copilot AI Jun 17, 2025

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.

Suggested change
if errors.As(err, &rawResponse) &&
rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound {
if rawResponse != nil && rawResponse.StatusCode == http.StatusNotFound {

Copilot uses AI. Check for mistakes.

helayoty and others added 3 commits June 24, 2025 18:32
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant