Skip to content

Commit

Permalink
fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
taraspos committed Dec 11, 2024
1 parent 549fcbd commit 7016d44
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tools/amplify-preview/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func main() {
// Check if Amplify branch is already connected to one of the Amplify Apps
branch, err := amp.FindExistingBranch(ctx, *gitBranchName)
if err != nil {
logger.Error("failed to lookup branch", logKeyBranchName, *gitBranchName, "error", err)
os.Exit(1)
}
if !(errors.Is(err, errNoJobForBranch) && *createBranches) {
logger.Error("failed to lookup branch", logKeyBranchName, *gitBranchName, "error", err)
os.Exit(1)
}

// If branch wasn't found, and branch creation enabled - create new branch
if branch == nil && *createBranches {
// If branch wasn't found, and branch creation enabled - create new branch
branch, err = amp.CreateBranch(ctx, *gitBranchName)
if err != nil {
logger.Error("failed to create branch", logKeyBranchName, *gitBranchName, "error", err)
Expand All @@ -83,11 +83,12 @@ func main() {
// check if existing branch was/being already deployed
job, err := amp.GetJob(ctx, branch, nil)
if err != nil {
logger.Error("failed to get amplify job", logKeyBranchName, *gitBranchName, "error", err)
os.Exit(1)
}
if !(errors.Is(err, errNoJobForBranch) && *createBranches) {
logger.Error("failed to get amplify job", logKeyBranchName, *gitBranchName, "error", err)
os.Exit(1)
}

if errors.Is(err, errNoJobForBranch) && *createBranches {
// if job not found and branch was just created - start new job
job, err = amp.StartJob(ctx, branch)
if err != nil {
logger.Error("failed to start amplify job", logKeyBranchName, *gitBranchName, "error", err)
Expand Down

0 comments on commit 7016d44

Please sign in to comment.