Skip to content

Conversation

@emirot
Copy link
Contributor

@emirot emirot commented Dec 7, 2025

What

Return error if resp is nil

Why

Nilway detected

/Users/nolan/Documents/oss/gitops-promoter/internal/scms/gitlab/utils.go:14:11: error: Potential nil panic detected. Observed nil flow from source to dereference point: 
        - [email protected]/merge_requests.go:327:23: unassigned variable `resp` returned from `ListMergeRequests()` in position 1
        - [email protected]/merge_requests.go:28:3: returned as result 1 from interface method `MergeRequestsServiceInterface.ListMergeRequests()` (implemented by `MergeRequestsService.ListMergeRequests()`)
        - gitlab/pullrequest.go:259:3: result 1 of `ListMergeRequests()` passed as arg `resp` to `logGitLabRateLimitsIfAvailable()` via the assignment(s):
                - `pr.client.MergeRequests.ListMergeRequests(...)` to `resp` at gitlab/pullrequest.go:249:7
        - gitlab/utils.go:14:11: function parameter `resp` accessed field `Header`

@codecov-commenter
Copy link

Bundle Report

Bundle size has no change ✅

@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2025

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.53%. Comparing base (1a04f7c) to head (f0d139d).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
internal/scms/gitlab/pullrequest.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #765      +/-   ##
==========================================
- Coverage   56.79%   56.53%   -0.26%     
==========================================
  Files          37       37              
  Lines        4004     4008       +4     
==========================================
- Hits         2274     2266       -8     
- Misses       1446     1455       +9     
- Partials      284      287       +3     

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

metrics.RecordSCMCall(repo, metrics.SCMAPIPullRequest, metrics.SCMOperationList, resp.StatusCode, time.Since(start), nil)
}
if err != nil {
return false, "", time.Time{}, fmt.Errorf("failed to list pull requests: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the gitlab client return an error for non-200 responses? If so, we still want to make sure we push the metric for the failed request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I see it does return an error for non-200 response code https://gitlab.com/gitlab-org/api/client-go/-/blob/main/merge_requests.go#L316

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I don't think we can move the metrics call down...

But we can still add the if resp == nil check, I think that's valid and fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @crenshaw-dev for the explanation, I have updated

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.

3 participants