Skip to content
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

ARO-3536: Add error handling when "CLUSTER" env variable is empty. #3007

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func IsCI() bool {
// Otherwise it returns nil.
func ValidateVars(vars ...string) error {
for _, v := range vars {
if _, found := os.LookupEnv(v); !found {
if v, found := os.LookupEnv(v); !found || v == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse the variable "v" here does not sound very good, sometimes it is dangerous and hard to debug, it have no problem in the case tho. it does not help for a good coding practice, how about change to another one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it does have problem here, in case the env variable is set to "", the error handling cannot print out the actual variable name, instead it only prints out an "" as v has been re-assigned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the error handling prints out
FATA[2023-07-20T18:23:54+12:00]hack/cluster/cluster.go:73 main.main() environment variable "" unset

I'll revise this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now updated this. Variable name is appearing now.

[ecardena@ed-thinkpad ARO-RP]$ CLUSTER=$CLUSTER go run ./hack/cluster create
FATA[2023-07-24T17:45:58+12:00]hack/cluster/cluster.go:73 main.main() environment variable "CLUSTER" unset         
exit status 1

return fmt.Errorf("environment variable %q unset", v)
}
}
Expand Down