Skip to content

Commit

Permalink
cmd: use log.Fatalf instead of calling fmt.Errorf
Browse files Browse the repository at this point in the history
Fatal force the program to exit, there is no return code for that,
because of that it also doesn't make sense to call Errorf() from within
a Fatal() call instead of directly calling Fatalf().

Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
  • Loading branch information
bmeneg committed Jun 15, 2021
1 parent efa4be2 commit e7f1c88
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/edit_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func getUpdateUsers(currentUsers []string, users []string, remove []string) ([]i
userIDs = make([]int, len(users))
for i, a := range users {
if getUserID(a) == nil {
return nil, false, fmt.Errorf("Error: %s is not a valid username\n", a)
return nil, false, fmt.Errorf("%s is not a valid username", a)
}
userIDs[i] = *getUserID(a)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func issueList(args []string) ([]*gitlab.Issue, error) {
if issueAuthor != "" {
issueAuthorID = getUserID(issueAuthor)
if issueAuthorID == nil {
log.Fatal(fmt.Errorf("%s user not found\n", issueAuthor))
log.Fatalf("%s user not found\n", issueAuthor)
}
}

if issueAssignee != "" {
issueAssigneeID = getUserID(issueAssignee)
if issueAssigneeID == nil {
log.Fatal(fmt.Errorf("%s user not found\n", issueAssignee))
log.Fatalf("%s user not found\n", issueAssignee)
}
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/mr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func init() {

func verifyRemoteAndBranch(projectID int, remote string, branch string) error {
if _, err := lab.GetCommit(projectID, branch); err != nil {
return fmt.Errorf("Aborting MR create, %s:%s is not a valid reference", remote, branch)
return fmt.Errorf("%s:%s is not a valid reference", remote, branch)
}
return nil
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func runMRCreate(cmd *cobra.Command, args []string) {
sourceRemote = sourceParts[0]
sourceBranch = sourceParts[1]
if sourceRemote == "" || sourceBranch == "" {
log.Fatal(fmt.Errorf("Error: Source remote must have format remote:remote_branch.\n"))
log.Fatalf("source remote must have format remote:remote_branch.\n")
}

_, err := git.IsRemote(sourceRemote)
Expand Down Expand Up @@ -154,7 +154,7 @@ func runMRCreate(cmd *cobra.Command, args []string) {
targetRemote = args[0]
ok, err := git.IsRemote(targetRemote)
if err != nil || !ok {
log.Fatal(fmt.Errorf("%s is not a valid remote\n", targetRemote))
log.Fatalf("%s is not a valid remote\n", targetRemote)
}
}
targetProjectName, err := git.PathWithNameSpace(targetRemote)
Expand Down Expand Up @@ -232,7 +232,7 @@ func runMRCreate(cmd *cobra.Command, args []string) {
}

if title == "" {
log.Fatal("aborting MR due to empty MR msg")
log.Fatal("empty MR message")
}

linebreak, _ := cmd.Flags().GetBool("force-linebreak")
Expand Down Expand Up @@ -293,7 +293,7 @@ func mrText(sourceRemote, sourceBranch, targetRemote, targetBranch string, cover
}
}
if numCommits == 0 {
return "", fmt.Errorf("Aborting: The resulting Merge Request from %s to %s has 0 commits", target, source)
return "", fmt.Errorf("the resulting MR from %s to %s has 0 commits", target, source)
}

tmpl := heredoc.Doc(`
Expand Down
6 changes: 3 additions & 3 deletions cmd/mr_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func mrList(args []string) ([]*gitlab.MergeRequest, error) {
if mrAssignee != "" {
mrAssigneeID = getUserID(mrAssignee)
if mrAssigneeID == nil {
log.Fatal(fmt.Errorf("%s user not found\n", mrAssignee))
log.Fatalf("%s user not found\n", mrAssignee)
}
} else if mrMine {
assigneeID, err := lab.UserID()
Expand All @@ -98,7 +98,7 @@ func mrList(args []string) ([]*gitlab.MergeRequest, error) {
if mrAuthor != "" {
mrAuthorID = getUserID(mrAuthor)
if mrAuthorID == nil {
log.Fatal(fmt.Errorf("%s user not found\n", mrAuthor))
log.Fatalf("%s user not found\n", mrAuthor)
}
}

Expand All @@ -113,7 +113,7 @@ func mrList(args []string) ([]*gitlab.MergeRequest, error) {
if mrReviewer != "" {
mrReviewerID = getUserID(mrReviewer)
if mrReviewerID == nil {
log.Fatal(fmt.Errorf("%s user not found\n", mrReviewer))
log.Fatalf("%s user not found\n", mrReviewer)
}
}

Expand Down

0 comments on commit e7f1c88

Please sign in to comment.