fix: use %w for error wrapping and add missing bounds check#2803
fix: use %w for error wrapping and add missing bounds check#2803Fortune-Ndlovu wants to merge 3 commits into
Conversation
Use %w instead of %s in fmt.Errorf calls to preserve the error chain for errors.Is/errors.As. Add a missing empty-slice guard in mergeDeployments to prevent a potential index-out-of-range panic, consistent with the existing check in mergeDynamicPlugins. Fix typo "reconsiled" -> "reconciled" in controller comment. Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
Code Review by Qodo
1.
|
Review Summary by QodoFix error wrapping and add missing bounds check
WalkthroughsDescription• Replace %s with %w in 6 fmt.Errorf calls to preserve error chains • Add missing bounds check in mergeDeployments to prevent index panic • Fix typo "reconsiled" to "reconciled" in controller comment Diagramflowchart LR
A["Error Wrapping Issues"] -->|Replace %s with %w| B["Preserve Error Chains"]
C["Missing Bounds Check"] -->|Add len check| D["Prevent Index Panic"]
E["Typo in Comment"] -->|Fix reconsiled| F["Correct Documentation"]
B --> G["Improved Error Handling"]
D --> G
F --> G
File Changes1. internal/controller/backstage_controller.go
|
Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
|
/review |
PR Reviewer Guide 🔍Warning
Here are some key observations to aid the review process:
|
Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
|
|
/agentic_review |
|
Persistent review updated to latest commit 368b1af |



Summary
This PR solves several small but important error handling and correctness issues across the operator:
%s->%w): 6fmt.Errorfcalls acrosspkg/model/runtime.goandinternal/controller/spec_preprocessor.goused%sinstead of%w, which dropped the error chain and brokeerrors.Is/errors.Asfor callersmergeDeployments:pkg/model/deployment.goaccessedobjs[0]without checking for an empty slice, which could panic and crash the controller. Added a guard consistent with the existing check inmergeDynamicPlugins, including source file paths in the error for debuggabilitypkg/model/runtime.goreported "failed to read default value" when the error was actually from reading overlay config, sending operators looking in the wrong place during debuggingTest plan
make testpasses, all unit and integration tests green