-
Notifications
You must be signed in to change notification settings - Fork 707
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
Don't panic in ParseDriverType #1363
Don't panic in ParseDriverType #1363
Conversation
Related discussion: vmware-tanzu#1359 (comment)
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, I have a couple of small comments, let me know what you think
cmd/kubeops/main.go
Outdated
driverType = agent.ParseDriverType(helmDriverArg) | ||
d, err := agent.ParseDriverType(helmDriverArg) | ||
if err != nil { | ||
panic(err.Error()) |
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.
you can just do panic(err)
@@ -90,16 +91,16 @@ func createStorage(driverType DriverType, namespace string, clientset *kubernete | |||
return store | |||
} | |||
|
|||
func ParseDriverType(raw string) DriverType { | |||
func ParseDriverType(raw string) (DriverType, error) { |
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.
this function is simple but it'd be good to have a simple test
I have fixed those issues now! 😃 |
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.
Thanks for the changes!
Description of the change
It rewrites
agent.ParseDriverType
to return an error instead of panicking if it doesn't recognize its input.Benefits
ParseDriverType
is made more faithful to its declared type.main.go
that the application may panic.Possible drawbacks
ParseDriverType
becomes more verbose.Applicable issues
Excerpt from a related discussion with @andresmgot in #1359: