refactor: improve code quality and error handling#4586
Open
bhargavpillati21 wants to merge 1 commit into
Open
Conversation
- Add bounds checking to ConcurrentErrorSlice.Last() to prevent panics on empty slices - Optimize readUnstructured() by removing unnecessary map initialization in JSON unmarshaling - Improve removeAllFromDir() error handling to properly distinguish between EOF and other errors - Fix redundant error logging in retryLister() by removing duplicate 'err' parameter - Initialize client field in upgrade Manager.New() instead of leaving it nil - Fix incorrect comment in upgrade Manager (audit -> upgrade)
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR tightens up several utility behaviors and logging, and refactors manager construction.
Changes:
- Refactor
upgrade.Managerconstructor to return an initialized struct literal (and update its doc comment). - Make
ConcurrentErrorSlice.Last()safe on empty slices by returningnil. - Improve audit dir cleanup error handling and simplify unstructured JSON unmarshalling; adjust readiness listing log message.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/upgrade/manager.go | Refactors New() and updates constructor behavior for the upgrade manager. |
| pkg/syncutil/concurrent_slice.go | Prevents panic in Last() when the slice is empty. |
| pkg/readiness/list.go | Tweaks error log message/fields when listing fails. |
| pkg/audit/manager.go | Fixes error handling when reading directory entries and simplifies JSON unmarshalling into Unstructured. |
Comment on lines
34
to
43
| mgr manager.Manager | ||
| } | ||
|
|
||
| // New creates a new manager for audit. | ||
| // New creates a new manager for upgrade. | ||
| func New(mgr manager.Manager) *Manager { | ||
| am := &Manager{ | ||
| mgr: mgr, | ||
| return &Manager{ | ||
| client: mgr.GetClient(), | ||
| mgr: mgr, | ||
| } | ||
| return am | ||
| } |
Contributor
|
@bhargavpillati21 can you fix DCO? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR includes targeted refactoring improvements to enhance code quality, error handling, and maintainability across key packages.
Changes
1. ConcurrentErrorSlice Safety (
pkg/syncutil/concurrent_slice.go)Last()method to prevent index out of range panicsnilfor empty slices instead of panicking2. Audit Manager Optimizations (
pkg/audit/manager.go)readUnstructured(): Removed unnecessary empty map initialization
removeAllFromDir(): Enhanced error handling
io.EOFand other errors3. Readiness Package (
pkg/readiness/list.go)retryLister()4. Upgrade Manager (
pkg/upgrade/manager.go)Improved initialization in
New()constructorFixed documentation: Corrected comment from "audit" to "upgrade"
Impact
Testing
All changes maintain existing functionality while improving implementation details. Code compiles successfully without errors.
Type