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

cli/silence_add: don't ingore errors when getting current user #1031

Merged
merged 1 commit into from
Oct 9, 2017

Conversation

iksaif
Copy link
Contributor

@iksaif iksaif commented Oct 6, 2017

I had a system where amtool would segfault on startup because of
that.

user, _ := user.Current()
addCmd.Flags().StringP("author", "a", user.Username, "Username for CreatedBy field")
user, err := user.Current()
username := ""
Copy link
Contributor

@josedonizetti josedonizetti Oct 6, 2017

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@iksaif iksaif force-pushed the criteo branch 2 times, most recently from 088de56 to 46a4e74 Compare October 6, 2017 09:34
username := ""

if err != nil {
fmt.Errorf("Failed to get current user")
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, fixed.

@iksaif
Copy link
Contributor Author

iksaif commented Oct 6, 2017

Ok, the error message should be correctly printed now :)


user, err := user.Current()
if err != nil {
fmt.Printf("Failed to get the current user, specify one with --author: %s\n", err)
Copy link
Contributor

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.

@iksaif
Copy link
Contributor Author

iksaif commented Oct 9, 2017

fixed

I had a system where amtool would segfault on startup because of
that.
@stuartnelson3 stuartnelson3 merged commit 21a2e53 into prometheus:master Oct 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants