-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure flagValue.String() can be called even when flagValue is created by reflect.New #11651
Make sure flagValue.String() can be called even when flagValue is created by reflect.New #11651
Conversation
…ated by reflect.New
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, does this need a changelog?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11651 +/- ##
==========================================
+ Coverage 91.58% 91.64% +0.05%
==========================================
Files 440 442 +2
Lines 23765 23751 -14
==========================================
Hits 21766 21766
+ Misses 1627 1616 -11
+ Partials 372 369 -3 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
…ated by reflect.New (open-telemetry#11651) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Make sure `flagValue.String()` can be called even when flagValue is created by `reflect.New` ```go import ( "flag" "log" "go.opentelemetry.io/collector/featuregate" ) func main() { fs := new(flag.FlagSet) featuregate.GlobalRegistry().RegisterFlags(fs) if err := fs.Parse([]string{"--help"}); err != nil { log.Fatalf("failed to parse flags: %v", err) } } ``` Before this PR ``` Usage: -feature-gates value Comma-delimited list of feature gate identifiers. Prefix with '-' to disable the feature. '+' or no prefix will enable the feature. panic calling String method on zero featuregate.flagValue for flag feature-gates: runtime error: invalid memory address or nil pointer dereference failed to parse flags: flag: help requested ``` Note that there is a panic in the message. After this PR ``` Usage: -feature-gates value Comma-delimited list of feature gate identifiers. Prefix with '-' to disable the feature. '+' or no prefix will enable the feature. failed to parse flags: flag: help requested ``` --------- Co-authored-by: Yang Song <songy23@users.noreply.github.com>
Description
Make sure
flagValue.String()
can be called even when flagValue is created byreflect.New
Before this PR
Note that there is a panic in the message.
After this PR