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

Improve error logging #111

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions go/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func init() {

err := cobra.MarkFlagRequired(rootCmd.PersistentFlags(), flags.MajorRelease)
if err != nil {
panic(err)
utils.BailOutE(err)
}
}

Expand All @@ -88,7 +88,7 @@ func Execute() {
os.Exit(0)
}
if err != nil {
panic(err)
utils.BailOutE(err)
}

if version {
Expand Down Expand Up @@ -149,12 +149,12 @@ func setUpVitessReleaseInformation(s *releaser.State, repo string, rc int) (rele
// if we want to do an RC-1 release and the branch is different from `main`, something is wrong
// and if we want to do an >= RC-2 release, the release as to be the latest AKA on the latest release branch
if rcIncrement >= 1 && !isLatestRelease {
utils.LogPanic(nil, "wanted: RC %d but release branch was %s, latest release was %v and is from main is %v", rcIncrement, releaseBranch, isLatestRelease, isFromMain)
utils.BailOut(nil, "wanted: RC %d but release branch was %s, latest release was %v and is from main is %v", rcIncrement, releaseBranch, isLatestRelease, isFromMain)
}

majorReleaseNb, err := strconv.Atoi(releaseVersion)
if err != nil {
utils.LogPanic(err, "could not parse the release version")
utils.BailOut(err, "could not parse the release version")
}

vitessRelease := releaser.ReleaseInformation{
Expand Down Expand Up @@ -210,7 +210,7 @@ func setUpIssueDate(s *releaser.State) {
}
parsedReleaseDate, err := time.Parse(time.DateOnly, releaseDate)
if err != nil {
panic(err)
utils.BailOutE(err)
}
s.Issue.Date = parsedReleaseDate
}
Expand Down
2 changes: 1 addition & 1 deletion go/releaser/code_freeze/code_freeze.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func CodeFreeze(state *releaser.State) (*logging.ProgressLogging, func() string)
func isCurrentBranchFrozen() bool {
b, err := os.ReadFile(codeFreezeWorkflowFile)
if err != nil {
utils.LogPanic(err, "failed to read file %s", codeFreezeWorkflowFile)
utils.BailOut(err, "failed to read file %s", codeFreezeWorkflowFile)
}
str := string(b)
return strings.Contains(str, "exit 1")
Expand Down
14 changes: 7 additions & 7 deletions go/releaser/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func CreateBranchAndCheckout(branch, base string) error {
if strings.Contains(out, fmt.Sprintf("a branch named '%s' already exists", branch)) {
return errBranchExists
}
utils.LogPanic(err, "got: %s", out)
utils.BailOut(err, "got: %s", out)
}
return nil
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func CommitAll(msg string) (empty bool) {
if strings.Contains(out, "nothing to commit, working tree clean") {
return true
}
utils.LogPanic(err, "got: %s", out)
utils.BailOut(err, "got: %s", out)
}
return false
}
Expand All @@ -107,17 +107,17 @@ func FindRemoteName(repository string) string {

func CorrectCleanRepo(repo string) {
if !checkCurrentRepo(repo + ".git") {
utils.LogPanic(nil, "failed to find remote %s in %s", repo, getWorkingDir())
utils.BailOut(nil, "failed to find remote %s in %s", repo, getWorkingDir())
}
if !cleanLocalState() {
utils.LogPanic(nil, "the %s repository should have a clean state", getWorkingDir())
utils.BailOut(nil, "the %s repository should have a clean state", getWorkingDir())
}
}

func getWorkingDir() string {
dir, err := os.Getwd()
if err != nil {
utils.LogPanic(err, "failed to find the current working dir")
utils.BailOut(err, "failed to find the current working dir")
}
return dir
}
Expand All @@ -133,7 +133,7 @@ func FindNewGeneratedBranch(remote, baseBranch, branchName string) string {
if errors.Is(err, errBranchExists) {
continue
}
utils.LogPanic(err, "bug should not get here")
utils.BailOut(err, "bug should not get here")
}
break
}
Expand All @@ -146,7 +146,7 @@ func TagAndPush(remote, tag string) (exists bool) {
if strings.Contains(out, "already exists") {
return true
}
utils.LogPanic(err, "got: %s", out)
utils.BailOut(err, "got: %s", out)
}

utils.Exec("git", "push", remote, tag)
Expand Down
8 changes: 4 additions & 4 deletions go/releaser/github/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func getBranchProtectionRules(repo string) fetchBranchProtectionRules {
var bpr fetchBranchProtectionRules
err := json.Unmarshal([]byte(stdOut), &bpr)
if err != nil {
utils.LogPanic(err, "failed to parse the branch protection rules")
utils.BailOut(err, "failed to parse the branch protection rules")
}
return bpr
}
Expand Down Expand Up @@ -190,17 +190,17 @@ func transformBranchProtectionRules(bpr fetchBranchProtectionRules) updateUpdate
func putBranchProtectionRules(ubpr updateUpdateBranchProtectionRulesPayload, repo, branch string) {
jsonUbpr, err := json.Marshal(ubpr)
if err != nil {
utils.LogPanic(err, "failed to marshal update branch protection rules")
utils.BailOut(err, "failed to marshal update branch protection rules")
}

f, err := os.CreateTemp("/tmp", "")
if err != nil {
utils.LogPanic(err, "failed to create a temporary file")
utils.BailOut(err, "failed to create a temporary file")
}

_, err = f.Write(jsonUbpr)
if err != nil {
utils.LogPanic(err, "failed to write update branch protection rules to the temporary file")
utils.BailOut(err, "failed to write update branch protection rules to the temporary file")
}

_ = execGh("api",
Expand Down
12 changes: 6 additions & 6 deletions go/releaser/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func execGh(args ...string) string {
stdOut, stdErr, err := gh.Exec(args...)
if err != nil {
cmd := append([]string{"gh"}, strings.Join(args, " "))
utils.LogPanic(err, "failed to execute: %s, got: %s", strings.Join(cmd, " "), stdOut.String()+stdErr.String())
utils.BailOut(err, "failed to execute: %s, got: %s", strings.Join(cmd, " "), stdOut.String()+stdErr.String())
}
return stdOut.String()
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func GetIssueTitleAndBody(repo string, nb int) (string, string) {
var i Issue
err := json.Unmarshal([]byte(stdOut), &i)
if err != nil {
utils.LogPanic(err, "failed to parse the issue number %d, got: %s", nb, stdOut)
utils.BailOut(err, "failed to parse the issue number %d, got: %s", nb, stdOut)
}
return i.Title, i.Body
}
Expand All @@ -117,7 +117,7 @@ func GetReleaseIssue(repo, release string, rcIncrement int) (string, string) {
var issues []map[string]string
err := json.Unmarshal([]byte(stdOut), &issues)
if err != nil {
utils.LogPanic(err, "failed to parse the release issue, got: %s", stdOut)
utils.BailOut(err, "failed to parse the release issue, got: %s", stdOut)
}

for _, issue := range issues {
Expand Down Expand Up @@ -150,7 +150,7 @@ func URLToNb(url string) int {
issueNbStr := url[lastIdx+1:]
nb, err := strconv.Atoi(issueNbStr)
if err != nil {
utils.LogPanic(err, "failed to convert the end of the GitHub URL to a number, got: %s", issueNbStr)
utils.BailOut(err, "failed to convert the end of the GitHub URL to a number, got: %s", issueNbStr)
}
return nb
}
Expand All @@ -170,7 +170,7 @@ func CheckReleaseBlockerIssues(repo, majorRelease string) map[string]any {
var issues []Issue
err := json.Unmarshal([]byte(stdOut), &issues)
if err != nil {
utils.LogPanic(err, "failed to parse the release blocker issue, got: %s", stdOut)
utils.BailOut(err, "failed to parse the release blocker issue, got: %s", stdOut)
}

var mustClose []Issue
Expand Down Expand Up @@ -206,7 +206,7 @@ func LoadKnownIssues(repo, majorRelease string) []Issue {
var knownIssues []Issue
err := json.Unmarshal([]byte(stdOut), &knownIssues)
if err != nil {
utils.LogPanic(err, "failed to parse known issues, got: %s", stdOut)
utils.BailOut(err, "failed to parse known issues, got: %s", stdOut)
}
return knownIssues
}
4 changes: 2 additions & 2 deletions go/releaser/github/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetMilestonesByName(repo, name string) []Milestone {
var ms []Milestone
err := json.Unmarshal([]byte(str), &ms)
if err != nil {
utils.LogPanic(err, "failed to parse milestone, got: %s", str)
utils.BailOut(err, "failed to parse milestone, got: %s", str)
}
return ms
}
Expand All @@ -62,7 +62,7 @@ func CreateNewMilestone(repo, name string) string {
func CloseMilestone(repo, name string) string {
ms := GetMilestonesByName(repo, name)
if len(ms) != 1 {
utils.LogPanic(nil, "expected to find one milestone found %d", len(ms))
utils.BailOut(nil, "expected to find one milestone found %d", len(ms))
}

stdOut := execGh(
Expand Down
10 changes: 5 additions & 5 deletions go/releaser/github/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func CheckBackportToPRs(repo, branch string) map[string]any {
var prs []PR
err := json.Unmarshal([]byte(stdOut), &prs)
if err != nil {
utils.LogPanic(err, "failed to parse backport PRs, got: %s", stdOut)
utils.BailOut(err, "failed to parse backport PRs, got: %s", stdOut)
}

var mustClose []PR
Expand Down Expand Up @@ -120,7 +120,7 @@ func CheckReleaseBlockerPRs(repo, majorRelease string) map[string]any {
var prs []PR
err := json.Unmarshal([]byte(stdOut), &prs)
if err != nil {
utils.LogPanic(err, "failed to parse the release blocker PRs, got: %s", stdOut)
utils.BailOut(err, "failed to parse the release blocker PRs, got: %s", stdOut)
}

var mustClose []PR
Expand Down Expand Up @@ -154,7 +154,7 @@ func FindPR(repo, prTitle string) (nb int, url string) {
var prs []PR
err := json.Unmarshal([]byte(stdOut), &prs)
if err != nil {
utils.LogPanic(err, "failed to parse PRs, got: %s", stdOut)
utils.BailOut(err, "failed to parse PRs, got: %s", stdOut)
}
for _, pr := range prs {
if pr.Title == prTitle {
Expand All @@ -176,7 +176,7 @@ func GetMergedPRsAndAuthorsByMilestone(repo, milestone string) (prs []PR, author

err := json.Unmarshal([]byte(stdOut), &prs)
if err != nil {
utils.LogPanic(err, "failed to parse PRs, got: %s", stdOut)
utils.BailOut(err, "failed to parse PRs, got: %s", stdOut)
}

// Get the full list of distinct PRs authors and sort them
Expand Down Expand Up @@ -207,7 +207,7 @@ func GetOpenedPRsByMilestone(repo, milestone string) []PR {
var prs []PR
err := json.Unmarshal([]byte(stdOut), &prs)
if err != nil {
utils.LogPanic(err, "failed to parse PRs, got: %s", stdOut)
utils.BailOut(err, "failed to parse PRs, got: %s", stdOut)
}
return prs
}
Expand Down
4 changes: 2 additions & 2 deletions go/releaser/github/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package github

import (
"fmt"
"log"
"strings"
"vitess.io/vitess-releaser/go/releaser/utils"

"vitess.io/vitess-releaser/go/releaser/git"
)
Expand Down Expand Up @@ -57,7 +57,7 @@ func CreateRelease(repo, tag, notesFilePath string, latest, prerelease bool) (ur
if strings.Contains(err.Error(), "already exists") {
return fmt.Sprintf("https://github.com/%s/releases/tag/%s", repo, tag)
}
log.Panic(err)
utils.BailOutE(err)
}
return strings.ReplaceAll(stdOut, "\n", "")
}
2 changes: 1 addition & 1 deletion go/releaser/github/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func CurrentUser() string {

err := json.Unmarshal([]byte(exec), &x)
if err != nil {
utils.LogPanic(err, "failed to parse the current user, got: %s", exec)
utils.BailOut(err, "failed to parse the current user, got: %s", exec)
}

return x["login"].(string)
Expand Down
8 changes: 4 additions & 4 deletions go/releaser/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (s *State) LoadIssue() {
if idx := strings.Index(title, "-RC"); idx != -1 {
rc, err := strconv.Atoi(title[idx+len("-RC"):])
if err != nil {
utils.LogPanic(err, "failed to parse the RC number from the release issue title (%s)", title)
utils.BailOut(err, "failed to parse the RC number from the release issue title (%s)", title)
}
newIssue.RC = rc
}
Expand All @@ -384,7 +384,7 @@ func (s *State) LoadIssue() {
nline = strings.ReplaceAll(nline, ".", "") // remove the period at the end of the line
parsedDate, err := time.Parse("Mon _2 Jan 2006", nline)
if err != nil {
utils.LogPanic(err, "failed to parse the date from the release issue body (%s)", nline)
utils.BailOut(err, "failed to parse the date from the release issue body (%s)", nline)
}
newIssue.Date = parsedDate
}
Expand Down Expand Up @@ -646,12 +646,12 @@ func (i *Issue) toString() string {

parsed, err := tmpl.Parse(releaseIssueTemplate)
if err != nil {
utils.LogPanic(err, "failed to parse the release issue template")
utils.BailOut(err, "failed to parse the release issue template")
}
b := bytes.NewBufferString("")
err = parsed.Execute(b, i)
if err != nil {
utils.LogPanic(err, "failed to execute/write the release issue template")
utils.BailOut(err, "failed to execute/write the release issue template")
}
return b.String()
}
Expand Down
2 changes: 1 addition & 1 deletion go/releaser/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func FindVersionAfterNextRelease(state *State) string {
for _, segment := range segments {
v, err := strconv.Atoi(segment)
if err != nil {
utils.LogPanic(err, "failed to convert release number segment to number (%s)", segment)
utils.BailOut(err, "failed to convert release number segment to number (%s)", segment)
}
segmentInts = append(segmentInts, v)
}
Expand Down
2 changes: 1 addition & 1 deletion go/releaser/pre_release/create_release_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func findFilesRecursive() []string {
return nil
})
if err != nil {
utils.LogPanic(err, "failed to find files recursively")
utils.BailOut(err, "failed to find files recursively")
}
}
return files
Expand Down
Loading