fix: downgrade 404 API responses from error to debug log level#2776
fix: downgrade 404 API responses from error to debug log level#2776KMI1011 wants to merge 1 commit into
Conversation
|
|
There was a problem hiding this comment.
Code Review
This pull request modifies the GitHub API call logging in pkg/provider/github/profiler.go to log 404 Not Found errors as debug messages instead of error messages. The review feedback points out a potential nil pointer dereference panic when accessing resp.StatusCode if the embedded Response field in github.Response is nil, and suggests adding a check for resp.Response != nil.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if err != nil { | ||
| logFields = append(logFields, "error", err.Error()) | ||
| v.Logger.Errorw("GitHub API call failed", logFields...) | ||
| if resp != nil && resp.StatusCode == http.StatusNotFound { |
There was a problem hiding this comment.
In Go, github.Response embeds *http.Response anonymously. If resp is non-nil but its embedded Response field is nil, accessing resp.StatusCode will trigger a nil pointer dereference panic. To prevent potential runtime panics, ensure resp.Response is also checked for nil before accessing resp.StatusCode, similar to the check performed in checkRateLimit.
| if resp != nil && resp.StatusCode == http.StatusNotFound { | |
| if resp != nil && resp.Response != nil && resp.StatusCode == http.StatusNotFound { |
There was a problem hiding this comment.
Will do, I just was wondering, is this portion its, the 'v.Logger.Errorw' line, is it asking for it to be removed from line 139? Because that line is specifically used as an 'else' to bring in a missing OWNER file friendly error code.
There was a problem hiding this comment.
This still needs to be addressed
|
ptal @zakisk |
theakshaypant
left a comment
There was a problem hiding this comment.
Thanks @KMI1011 for working on this!
I have some minor comments on these changes.
| } | ||
|
|
||
| // Log based on success/failure with appropriate level | ||
| // Plausible replacement for the if err != nil |
There was a problem hiding this comment.
This comment looks out of place, suggest changing to something like
// Log based on success/failure with appropriate level.
// 404 responses are expected in some flows (e.g., missing OWNERS file)
// and are logged at debug level to avoid noisy error logs.
There was a problem hiding this comment.
+1
With code comments, my rule of thumb is the comment should explain "why does this work in this way" or (when it's not obvious) "why is this necessary".
I might annotate some code with comments about what needs to change and where, when I'm planning a change, but those comments should be removed before the change is opened for review 👍🏼
| if resp != nil && resp.StatusCode == http.StatusNotFound { | ||
| v.Logger.Debugw("GitHub API call returned not found", logFields...) |
There was a problem hiding this comment.
Suggest adding a test case for this new branch
aThorp96
left a comment
There was a problem hiding this comment.
Downgrading from Error to Debug might be too severe. For OWNERS files I think it makes sense, but are there other cases where a 404 should result in this error log? Should it be logged at Info or Warning instead of Debug? What do you think @theakshaypant ?
| } | ||
|
|
||
| // Log based on success/failure with appropriate level | ||
| // Plausible replacement for the if err != nil |
There was a problem hiding this comment.
+1
With code comments, my rule of thumb is the comment should explain "why does this work in this way" or (when it's not obvious) "why is this necessary".
I might annotate some code with comments about what needs to change and where, when I'm planning a change, but those comments should be removed before the change is opened for review 👍🏼
| if err != nil { | ||
| logFields = append(logFields, "error", err.Error()) | ||
| v.Logger.Errorw("GitHub API call failed", logFields...) | ||
| if resp != nil && resp.StatusCode == http.StatusNotFound { |
@aThorp96 This was almost a nit from me. I've been going back and forth on this myself. |
84b0d99 to
eb36e13
Compare
| Khiar Ibrahim | ||
|
|
There was a problem hiding this comment.
I think this was included by mistake
|
|
||
| // Log based on success/failure with appropriate level | ||
| // Log success/failure appropriately; 404 is debug-only | ||
| // since a missing OWNERS file is a valid/expected state. |
There was a problem hiding this comment.
Nitpick, wording, I think there are probably other 404s that are ok
| // since a missing OWNERS file is a valid/expected state. | |
| // since it's valid/expected in some cases, such as a missing OWNERS file. |
| if err != nil { | ||
| logFields = append(logFields, "error", err.Error()) | ||
| v.Logger.Errorw("GitHub API call failed", logFields...) | ||
| if resp != nil && resp.StatusCode == http.StatusNotFound { |
There was a problem hiding this comment.
This still needs to be addressed
|
I like the additional test case and I appreciate combining it with the existing test case. A couple small feedback comments. The |
|
/ok-to-test |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2776 +/- ##
=======================================
Coverage 59.77% 59.77%
=======================================
Files 210 210
Lines 21135 21141 +6
=======================================
+ Hits 12633 12638 +5
- Misses 7707 7708 +1
Partials 795 795 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
I had planned to keep my update to it, however that was one of the things the pre commit requested I compress. It was the first of my fixes after committing. Should I revert back to the change I initially addressed and apply --no-verify? |
I think it's suggesting you compress |
|
@KMI1011 yes, just use |
eb36e13 to
188250d
Compare
188250d to
fff1dac
Compare
|
/ok-to-test |
Replace duplicate 404 and non-404 error subtests with a table-driven test to satisfy the dupl linter. Fixes tektoncd#2653 rh-pre-commit.version: 2.4.0 rh-pre-commit.check-secrets: ENABLED
80a8452 to
157386e
Compare
|
/ok-to-test |
rh-pre-commit.version: 2.4.0
rh-pre-commit.check-secrets: ENABLED
📝 Description of the Change
OWNERS file being missing lead to displaying a misconstruing Error message. logAPICall logged all API errors at Error level, making missing-file 404s look like real failures. Now, 404 responses are logged at Debug level instead, keeping controller logs clean for normal cases like a missing OWNERS file.
🔗 Linked GitHub Issue
#2653
Fixes #
🧪 Testing Strategy
🤖 AI Assistance
AI assistance can be used for various tasks, such as code generation,
documentation, or testing.
Please indicate whether you have used AI assistance
for this PR and provide details if applicable.
Important
Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.
If the majority of the code in this PR was generated by an AI, please add a
Co-authored-bytrailer to your commit message.For example:
Co-authored-by: Claude noreply@anthropic.com
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit installtoautomate these checks.