Skip to content

Commit 7e99332

Browse files
tgulacsibarelyhuman
authored andcommitted
Only call log.Fatal in main(), nowhere else
log.Fatal terminates the program - better propagate the error up to main()
1 parent 3083d91 commit 7e99332

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,27 @@ func Main() error {
7575
logContainer.Add("", s)
7676
}
7777

78-
if isCommitToNearestTag(r, c, tillLatest) {
78+
if nearest, err := isCommitToNearestTag(r, c, tillLatest); err != nil {
79+
return err
80+
} else if nearest {
7981
break
8082
}
8183
}
8284

8385
return logcategory.WriteMarkdown(os.Stdout, logContainer)
8486
}
8587

86-
func isCommitToNearestTag(repository *git.Repository, commit *object.Commit, tillLatest bool) bool {
88+
func isCommitToNearestTag(repository *git.Repository, commit *object.Commit, tillLatest bool) (bool, error) {
8789
latestTag, previousTag, err := repo.GetLatestTagFromRepository(repository)
88-
8990
if err != nil {
90-
log.Fatal("Couldn't get latest tag...", err)
91+
return false, fmt.Errorf("get latest tag: %w", err)
9192
}
9293

93-
if latestTag != nil {
94-
if tillLatest {
95-
return latestTag.Hash().String() == commit.Hash.String()
96-
}
97-
return previousTag.Hash().String() == commit.Hash.String()
98-
94+
if latestTag == nil {
95+
return false, nil
96+
}
97+
if tillLatest {
98+
return latestTag.Hash().String() == commit.Hash.String(), nil
9999
}
100-
return false
100+
return previousTag.Hash().String() == commit.Hash.String(), nil
101101
}

0 commit comments

Comments
 (0)