fix: replace reflect.Ptr with reflect.Pointer to fix govet inline#872
Conversation
There was a problem hiding this comment.
Pull request overview
Updates reflection kind checks to use reflect.Pointer instead of the deprecated reflect.Ptr alias, aligning the codebase with newer govet/golangci-lint expectations.
Changes:
- Replaced
reflect.Ptrwithreflect.Pointerin config value extraction logic. - Replaced
reflect.Ptrwithreflect.Pointerin Harbor error payload introspection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/utils/reflect.go | Updates pointer-kind checks used when extracting configuration values via reflection. |
| pkg/utils/error.go | Updates pointer-kind check used when reflecting into error payloads. |
Comments suppressed due to low confidence (1)
pkg/utils/error.go:41
ParseHarborErrorMsgcan panic here: (1) iferris an interface holding a typed-nil pointer,val.Kind() == reflect.Pointerandval.Elem()will panic unless you guard with!val.IsNil(). (2)FieldByNamerequiresval.Kind() == reflect.Struct; for error implementations that are not structs/pointers-to-structs, callingFieldByName("Payload")will panic. Consider checkingval.IsNil()beforeElem(), and returningerr.Error()early when the dereferenced value is not a struct.
val := reflect.ValueOf(err)
if val.Kind() == reflect.Pointer {
val = val.Elem()
}
field := val.FieldByName("Payload")
if field.IsValid() {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@Sypher845 PTAL |
|
@Yashbhu Thank you for contributing, LGTM. Rebase with main, and let one of the maintainers approve. |
…t error The updated golangci-lint govet analyzer flags reflect.Ptr as a deprecated alias that should be replaced with the canonical reflect.Pointer constant (introduced in Go 1.18). Affected files: - pkg/utils/error.go - pkg/utils/reflect.go - pkg/views/info/list/view.go - cmd/harbor/root/context/get.go - cmd/harbor/root/context/delete.go - cmd/harbor/root/context/update.go Signed-off-by: yash bahuguna <yashbahuguna918@gmail.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #872 +/- ##
=========================================
- Coverage 10.99% 9.00% -1.99%
=========================================
Files 173 272 +99
Lines 8671 13441 +4770
=========================================
+ Hits 953 1211 +258
- Misses 7612 12115 +4503
- Partials 106 115 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
reflect.Ptr lately started to trigger govet checks [1]. Since it is deprecated anyways [2], replace with reflect.Pointer. [1] - goharbor/harbor-cli#872 [2] - https://go-review.googlesource.com/c/go/+/359175 Signed-off-by: Michal Gorlas <michal.gorlas@9elements.com>
reflect.Ptr lately started to trigger govet checks [1]. Since it is deprecated anyways [2], replace with reflect.Pointer. [1] - goharbor/harbor-cli#872 [2] - https://go-review.googlesource.com/c/go/+/359175 Signed-off-by: Michal Gorlas <michal.gorlas@9elements.com>
The updated golangci-lint govet analyzer flags reflect.Ptr as a deprecated alias that should be replaced with the canonical reflect.Pointer constant (introduced in Go 1.18).
Affected files:
Description
Briefly describe what this pull request does and why the change is needed.
govetinline lint failure #870Type of Change
Please select the relevant type.
Changes