-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
cli/silence_add: don't ingore errors when getting current user #1031
Conversation
cli/silence_add.go
Outdated
user, _ := user.Current() | ||
addCmd.Flags().StringP("author", "a", user.Username, "Username for CreatedBy field") | ||
user, err := user.Current() | ||
username := "" |
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.
as a zero value string using var username string
reads better, what do u think?
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.
done
088de56
to
46a4e74
Compare
cli/silence_add.go
Outdated
username := "" | ||
|
||
if err != nil { | ||
fmt.Errorf("Failed to get current user") |
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 doesn't actually do anything -- it creates an error
but doesn't indicate it to the user. It would be useful to let the user know that they don't have a default username available, and that they'll have to provide one (since we require an author
when creating silences).
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.
right, fixed.
Ok, the error message should be correctly printed now :) |
cli/silence_add.go
Outdated
|
||
user, err := user.Current() | ||
if err != nil { | ||
fmt.Printf("Failed to get the current user, specify one with --author: %s\n", err) |
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.
It's typical in go to have the first letter of a log or print statement be lowercase, so failed
instead of Failed
. Also, err is of type error
, which is printed out with %v
. Once that's done, good to go.
fixed |
I had a system where amtool would segfault on startup because of that.
I had a system where amtool would segfault on startup because of
that.